@streamflow/stream 5.6.7 → 5.7.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.
@@ -16,23 +16,23 @@ export default class SolanaStreamClient extends BaseStreamClient {
16
16
  * Creates a new stream/vesting contract.
17
17
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
18
18
  */
19
- create({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: ICreateStreamData, { sender, isNative }: ICreateStreamSolanaExt): Promise<ICreateResult>;
19
+ create({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: ICreateStreamData, { sender, metadataPubKeys, isNative }: ICreateStreamSolanaExt): Promise<ICreateResult>;
20
20
  /**
21
21
  * Creates a new stream/vesting contract using unchecked instruction.
22
22
  *
23
- * Unchecked instruction differes from the regular in:
23
+ * Unchecked instruction differs from the regular in:
24
24
  * - does not check for initialized associated token account (wallets with no control over their ATA should not be used
25
25
  * as sender/recipient/partner or there are risks of funds being locked in the contract)
26
26
  * - initialized contract PDA off chain
27
27
  *
28
28
  * If you are not sure if you should use create or create_unchecked, go for create to be safer.
29
29
  */
30
- createUnchecked({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: ICreateStreamData, { sender, isNative }: ICreateStreamSolanaExt): Promise<ICreateResult>;
30
+ createUnchecked({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: ICreateStreamData, { sender, metadataPubKeys, isNative }: ICreateStreamSolanaExt): Promise<ICreateResult>;
31
31
  /**
32
32
  * Creates multiple stream/vesting contracts.
33
33
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
34
34
  */
35
- createMultiple(data: ICreateMultipleStreamData, { sender, isNative }: ICreateStreamSolanaExt): Promise<IMultiTransactionResult>;
35
+ createMultiple(data: ICreateMultipleStreamData, { sender, metadataPubKeys, isNative }: ICreateStreamSolanaExt): Promise<IMultiTransactionResult>;
36
36
  /**
37
37
  * Attempts withdrawing from the specified stream.
38
38
  */
@@ -69,4 +69,8 @@ export default class SolanaStreamClient extends BaseStreamClient {
69
69
  * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
70
70
  */
71
71
  private prepareStreamTransaction;
72
+ /**
73
+ * Utility function to generate metadata for a Contract or return existing Pubkey
74
+ */
75
+ private getOrCreateStreamMetadata;
72
76
  }
@@ -142,12 +142,12 @@ var SolanaStreamClient = /** @class */ (function (_super) {
142
142
  */
143
143
  SolanaStreamClient.prototype.create = function (_a, _b) {
144
144
  var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d, partner = _a.partner;
145
- var sender = _b.sender, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
145
+ var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
146
146
  return __awaiter(this, void 0, void 0, function () {
147
- var ixs, mintPublicKey, recipientPublicKey, metadata, _f, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, nativeInstructions, _g, commitment, hash, tx, signature;
148
- var _h;
149
- return __generator(this, function (_j) {
150
- switch (_j.label) {
147
+ var ixs, mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, _g, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, nativeInstructions, _h, commitment, hash, tx, signature;
148
+ var _j;
149
+ return __generator(this, function (_k) {
150
+ switch (_k.label) {
151
151
  case 0:
152
152
  if (!sender.publicKey) {
153
153
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
@@ -155,33 +155,31 @@ var SolanaStreamClient = /** @class */ (function (_super) {
155
155
  ixs = [];
156
156
  mintPublicKey = isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(mint);
157
157
  recipientPublicKey = new web3_js_1.PublicKey(recipient);
158
- metadata = web3_js_1.Keypair.generate();
159
- return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
160
- case 1:
161
- _f = __read.apply(void 0, [_j.sent(), 1]), escrowTokens = _f[0];
158
+ _f = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _f.metadata, metadataPubKey = _f.metadataPubKey;
159
+ _g = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _g[0];
162
160
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
163
- case 2:
164
- senderTokens = _j.sent();
161
+ case 1:
162
+ senderTokens = _k.sent();
165
163
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
166
- case 3:
167
- recipientTokens = _j.sent();
164
+ case 2:
165
+ recipientTokens = _k.sent();
168
166
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
169
- case 4:
170
- streamflowTreasuryTokens = _j.sent();
167
+ case 3:
168
+ streamflowTreasuryTokens = _k.sent();
171
169
  partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
172
170
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
173
- case 5:
174
- partnerTokens = _j.sent();
175
- if (!isNative) return [3 /*break*/, 7];
171
+ case 4:
172
+ partnerTokens = _k.sent();
173
+ if (!isNative) return [3 /*break*/, 6];
176
174
  return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
175
+ case 5:
176
+ _h = _k.sent();
177
+ return [3 /*break*/, 7];
177
178
  case 6:
178
- _g = _j.sent();
179
- return [3 /*break*/, 8];
179
+ _h = [];
180
+ _k.label = 7;
180
181
  case 7:
181
- _g = [];
182
- _j.label = 8;
183
- case 8:
184
- nativeInstructions = _g;
182
+ nativeInstructions = _h;
185
183
  ixs.push((0, instructions_1.createStreamInstruction)({
186
184
  start: new bn_js_1.default(start),
187
185
  depositedAmount: depositedAmount,
@@ -201,7 +199,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
201
199
  sender: sender.publicKey,
202
200
  senderTokens: senderTokens,
203
201
  recipient: new web3_js_1.PublicKey(recipient),
204
- metadata: metadata.publicKey,
202
+ metadata: metadataPubKey,
205
203
  escrowTokens: escrowTokens,
206
204
  recipientTokens: recipientTokens,
207
205
  streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
@@ -219,18 +217,20 @@ var SolanaStreamClient = /** @class */ (function (_super) {
219
217
  }));
220
218
  commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
221
219
  return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
222
- case 9:
223
- hash = _j.sent();
224
- tx = (_h = new web3_js_1.Transaction({
220
+ case 8:
221
+ hash = _k.sent();
222
+ tx = (_j = new web3_js_1.Transaction({
225
223
  feePayer: sender.publicKey,
226
224
  blockhash: hash.blockhash,
227
225
  lastValidBlockHeight: hash.lastValidBlockHeight,
228
- })).add.apply(_h, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
229
- tx.partialSign(metadata);
226
+ })).add.apply(_j, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
227
+ if (metadata) {
228
+ tx.partialSign(metadata);
229
+ }
230
230
  return [4 /*yield*/, this.sign(sender, tx, hash)];
231
- case 10:
232
- signature = _j.sent();
233
- return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadata.publicKey.toBase58() }];
231
+ case 9:
232
+ signature = _k.sent();
233
+ return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
234
234
  }
235
235
  });
236
236
  });
@@ -238,7 +238,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
238
238
  /**
239
239
  * Creates a new stream/vesting contract using unchecked instruction.
240
240
  *
241
- * Unchecked instruction differes from the regular in:
241
+ * Unchecked instruction differs from the regular in:
242
242
  * - does not check for initialized associated token account (wallets with no control over their ATA should not be used
243
243
  * as sender/recipient/partner or there are risks of funds being locked in the contract)
244
244
  * - initialized contract PDA off chain
@@ -247,46 +247,44 @@ var SolanaStreamClient = /** @class */ (function (_super) {
247
247
  */
248
248
  SolanaStreamClient.prototype.createUnchecked = function (_a, _b) {
249
249
  var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d, partner = _a.partner;
250
- var sender = _b.sender, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
250
+ var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
251
251
  return __awaiter(this, void 0, void 0, function () {
252
- var mintPublicKey, recipientPublicKey, metadata, rentToExempt, createMetadataInstruction, _f, escrowTokens, senderTokens, partnerPublicKey, nativeInstructions, _g, createInstruction, commitment, ixs, hash, tx, signature;
253
- var _h;
254
- return __generator(this, function (_j) {
255
- switch (_j.label) {
252
+ var mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, rentToExempt, createMetadataInstruction, _g, escrowTokens, senderTokens, partnerPublicKey, nativeInstructions, _h, createInstruction, commitment, ixs, hash, tx, signature;
253
+ var _j;
254
+ return __generator(this, function (_k) {
255
+ switch (_k.label) {
256
256
  case 0:
257
257
  if (!sender.publicKey) {
258
258
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
259
259
  }
260
260
  mintPublicKey = new web3_js_1.PublicKey(mint);
261
261
  recipientPublicKey = new web3_js_1.PublicKey(recipient);
262
- metadata = web3_js_1.Keypair.generate();
262
+ _f = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _f.metadata, metadataPubKey = _f.metadataPubKey;
263
263
  return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
264
264
  case 1:
265
- rentToExempt = _j.sent();
265
+ rentToExempt = _k.sent();
266
266
  createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
267
267
  programId: this.programId,
268
268
  space: METADATA_ACC_SIZE,
269
269
  lamports: rentToExempt,
270
270
  fromPubkey: sender === null || sender === void 0 ? void 0 : sender.publicKey,
271
- newAccountPubkey: metadata.publicKey,
271
+ newAccountPubkey: metadataPubKey,
272
272
  });
273
- return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
274
- case 2:
275
- _f = __read.apply(void 0, [_j.sent(), 1]), escrowTokens = _f[0];
273
+ _g = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _g[0];
276
274
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
277
- case 3:
278
- senderTokens = _j.sent();
275
+ case 2:
276
+ senderTokens = _k.sent();
279
277
  partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
280
- if (!isNative) return [3 /*break*/, 5];
278
+ if (!isNative) return [3 /*break*/, 4];
281
279
  return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
280
+ case 3:
281
+ _h = _k.sent();
282
+ return [3 /*break*/, 5];
282
283
  case 4:
283
- _g = _j.sent();
284
- return [3 /*break*/, 6];
284
+ _h = [];
285
+ _k.label = 5;
285
286
  case 5:
286
- _g = [];
287
- _j.label = 6;
288
- case 6:
289
- nativeInstructions = _g;
287
+ nativeInstructions = _h;
290
288
  createInstruction = (0, instructions_1.createUncheckedStreamInstruction)({
291
289
  start: new bn_js_1.default(start),
292
290
  depositedAmount: depositedAmount,
@@ -307,7 +305,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
307
305
  }, this.programId, {
308
306
  sender: sender.publicKey,
309
307
  senderTokens: senderTokens,
310
- metadata: metadata.publicKey,
308
+ metadata: metadataPubKey,
311
309
  escrowTokens: escrowTokens,
312
310
  mint: new web3_js_1.PublicKey(mint),
313
311
  feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
@@ -320,18 +318,20 @@ var SolanaStreamClient = /** @class */ (function (_super) {
320
318
  commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
321
319
  ixs = [createMetadataInstruction, createInstruction];
322
320
  return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
323
- case 7:
324
- hash = _j.sent();
325
- tx = (_h = new web3_js_1.Transaction({
321
+ case 6:
322
+ hash = _k.sent();
323
+ tx = (_j = new web3_js_1.Transaction({
326
324
  feePayer: sender.publicKey,
327
325
  blockhash: hash.blockhash,
328
326
  lastValidBlockHeight: hash.lastValidBlockHeight,
329
- })).add.apply(_h, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
330
- tx.partialSign(metadata);
327
+ })).add.apply(_j, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
328
+ if (metadata) {
329
+ tx.partialSign(metadata);
330
+ }
331
331
  return [4 /*yield*/, this.sign(sender, tx, hash)];
332
- case 8:
333
- signature = _j.sent();
334
- return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadata.publicKey.toBase58() }];
332
+ case 7:
333
+ signature = _k.sent();
334
+ return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
335
335
  }
336
336
  });
337
337
  });
@@ -341,13 +341,13 @@ var SolanaStreamClient = /** @class */ (function (_super) {
341
341
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
342
342
  */
343
343
  SolanaStreamClient.prototype.createMultiple = function (data, _a) {
344
- var sender = _a.sender, _b = _a.isNative, isNative = _b === void 0 ? false : _b;
344
+ var sender = _a.sender, metadataPubKeys = _a.metadataPubKeys, _b = _a.isNative, isNative = _b === void 0 ? false : _b;
345
345
  return __awaiter(this, void 0, void 0, function () {
346
- var recipients, metadatas, metadataToRecipient, errors, signatures, batch, recipients_1, recipients_1_1, recipientData, _c, tx, metadata, metadataPubKey, e_1_1, totalDepositedAmount, nativeInstructions, commitment, hash, prepareTransaction, signedBatch, prepareTx, batchTransactionsCalls, responses, successes, failures, metadataIds;
347
- var e_1, _d, _e;
346
+ var recipients, metadatas, metadataToRecipient, errors, signatures, batch, i, recipientData, _c, tx, metadataPubKey, totalDepositedAmount, nativeInstructions, commitment, hash, prepareTransaction, signedBatch, prepareTx, responses, signedBatch_1, signedBatch_1_1, batchTx, _d, _e, _f, _g, e_1_1, batchTransactionsCalls, _h, _j, _k, _l, successes, failures;
347
+ var _m, e_1, _o;
348
348
  var _this = this;
349
- return __generator(this, function (_f) {
350
- switch (_f.label) {
349
+ return __generator(this, function (_p) {
350
+ switch (_p.label) {
351
351
  case 0:
352
352
  recipients = data.recipients;
353
353
  if (!sender.publicKey) {
@@ -358,74 +358,101 @@ var SolanaStreamClient = /** @class */ (function (_super) {
358
358
  errors = [];
359
359
  signatures = [];
360
360
  batch = [];
361
- _f.label = 1;
361
+ metadataPubKeys = metadataPubKeys || [];
362
+ i = 0;
363
+ _p.label = 1;
362
364
  case 1:
363
- _f.trys.push([1, 6, 7, 8]);
364
- recipients_1 = __values(recipients), recipients_1_1 = recipients_1.next();
365
- _f.label = 2;
366
- case 2:
367
- if (!!recipients_1_1.done) return [3 /*break*/, 5];
368
- recipientData = recipients_1_1.value;
365
+ if (!(i < recipients.length)) return [3 /*break*/, 4];
366
+ recipientData = recipients[i];
369
367
  return [4 /*yield*/, this.prepareStreamTransaction(recipientData, data, {
370
368
  sender: sender,
369
+ metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
371
370
  })];
372
- case 3:
373
- _c = _f.sent(), tx = _c.tx, metadata = _c.metadata;
374
- metadataPubKey = metadata.publicKey.toBase58();
375
- metadataToRecipient[metadataPubKey] = recipientData;
376
- metadatas.push(metadata);
371
+ case 2:
372
+ _c = _p.sent(), tx = _c.tx, metadataPubKey = _c.metadataPubKey;
373
+ metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
374
+ metadatas.push(metadataPubKey.toBase58());
377
375
  batch.push({ tx: tx, recipient: recipientData.recipient });
378
- _f.label = 4;
376
+ _p.label = 3;
377
+ case 3:
378
+ i++;
379
+ return [3 /*break*/, 1];
379
380
  case 4:
380
- recipients_1_1 = recipients_1.next();
381
- return [3 /*break*/, 2];
382
- case 5: return [3 /*break*/, 8];
383
- case 6:
384
- e_1_1 = _f.sent();
385
- e_1 = { error: e_1_1 };
386
- return [3 /*break*/, 8];
387
- case 7:
388
- try {
389
- if (recipients_1_1 && !recipients_1_1.done && (_d = recipients_1.return)) _d.call(recipients_1);
390
- }
391
- finally { if (e_1) throw e_1.error; }
392
- return [7 /*endfinally*/];
393
- case 8:
394
- if (!isNative) return [3 /*break*/, 11];
381
+ if (!isNative) return [3 /*break*/, 7];
395
382
  totalDepositedAmount = recipients.reduce(function (acc, recipient) { return recipient.amount.add(acc); }, new bn_js_1.default(0));
396
383
  return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
397
- case 9:
398
- nativeInstructions = _f.sent();
384
+ case 5:
385
+ nativeInstructions = _p.sent();
399
386
  commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
400
387
  return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
401
- case 10:
402
- hash = _f.sent();
403
- prepareTransaction = (_e = new web3_js_1.Transaction({
388
+ case 6:
389
+ hash = _p.sent();
390
+ prepareTransaction = (_m = new web3_js_1.Transaction({
404
391
  feePayer: sender.publicKey,
405
392
  blockhash: hash.blockhash,
406
393
  lastValidBlockHeight: hash.lastValidBlockHeight,
407
- })).add.apply(_e, __spreadArray([], __read(nativeInstructions), false));
394
+ })).add.apply(_m, __spreadArray([], __read(nativeInstructions), false));
408
395
  batch.push({ tx: prepareTransaction, recipient: sender.publicKey.toBase58() });
409
- _f.label = 11;
410
- case 11: return [4 /*yield*/, (0, utils_1.signAllTransactionWithRecipients)(sender, batch)];
411
- case 12:
412
- signedBatch = _f.sent();
396
+ _p.label = 7;
397
+ case 7: return [4 /*yield*/, (0, utils_1.signAllTransactionWithRecipients)(sender, batch)];
398
+ case 8:
399
+ signedBatch = _p.sent();
413
400
  signedBatch.forEach(function (item, index) {
414
401
  item.tx.lastValidBlockHeight = batch[index].tx.lastValidBlockHeight;
415
402
  });
416
- if (!isNative) return [3 /*break*/, 14];
403
+ if (!isNative) return [3 /*break*/, 10];
417
404
  prepareTx = signedBatch.pop();
418
405
  return [4 /*yield*/, (0, utils_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx)];
406
+ case 9:
407
+ _p.sent();
408
+ _p.label = 10;
409
+ case 10:
410
+ responses = [];
411
+ if (!(metadataPubKeys.length > 0)) return [3 /*break*/, 19];
412
+ _p.label = 11;
413
+ case 11:
414
+ _p.trys.push([11, 16, 17, 18]);
415
+ signedBatch_1 = __values(signedBatch), signedBatch_1_1 = signedBatch_1.next();
416
+ _p.label = 12;
417
+ case 12:
418
+ if (!!signedBatch_1_1.done) return [3 /*break*/, 15];
419
+ batchTx = signedBatch_1_1.value;
420
+ _e = (_d = responses.push).apply;
421
+ _f = [responses];
422
+ _g = [[]];
423
+ return [4 /*yield*/, Promise.allSettled([
424
+ (0, utils_1.sendAndConfirmStreamRawTransaction)(this.connection, batchTx),
425
+ ])];
419
426
  case 13:
420
- _f.sent();
421
- _f.label = 14;
427
+ _e.apply(_d, _f.concat([__spreadArray.apply(void 0, _g.concat([__read.apply(void 0, [(_p.sent())]), false]))]));
428
+ _p.label = 14;
422
429
  case 14:
430
+ signedBatch_1_1 = signedBatch_1.next();
431
+ return [3 /*break*/, 12];
432
+ case 15: return [3 /*break*/, 18];
433
+ case 16:
434
+ e_1_1 = _p.sent();
435
+ e_1 = { error: e_1_1 };
436
+ return [3 /*break*/, 18];
437
+ case 17:
438
+ try {
439
+ if (signedBatch_1_1 && !signedBatch_1_1.done && (_o = signedBatch_1.return)) _o.call(signedBatch_1);
440
+ }
441
+ finally { if (e_1) throw e_1.error; }
442
+ return [7 /*endfinally*/];
443
+ case 18: return [3 /*break*/, 21];
444
+ case 19:
423
445
  batchTransactionsCalls = signedBatch.map(function (el) {
424
446
  return (0, utils_1.sendAndConfirmStreamRawTransaction)(_this.connection, el);
425
447
  });
448
+ _j = (_h = responses.push).apply;
449
+ _k = [responses];
450
+ _l = [[]];
426
451
  return [4 /*yield*/, Promise.allSettled(batchTransactionsCalls)];
427
- case 15:
428
- responses = _f.sent();
452
+ case 20:
453
+ _j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(_p.sent())]), false]))]));
454
+ _p.label = 21;
455
+ case 21:
429
456
  successes = responses
430
457
  .filter(function (el) { return el.status === "fulfilled"; })
431
458
  .map(function (el) { return el.value; });
@@ -434,8 +461,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
434
461
  .filter(function (el) { return el.status === "rejected"; })
435
462
  .map(function (el) { return (__assign(__assign({}, el.reason), { contractErrorCode: _this.extractErrorCode(el.reason.error) || undefined })); });
436
463
  errors.push.apply(errors, __spreadArray([], __read(failures), false));
437
- metadataIds = metadatas.map(function (pk) { return pk.publicKey.toBase58(); });
438
- return [2 /*return*/, { txs: signatures, metadatas: metadataIds, metadataToRecipient: metadataToRecipient, errors: errors }];
464
+ return [2 /*return*/, { txs: signatures, metadatas: metadatas, metadataToRecipient: metadataToRecipient, errors: errors }];
439
465
  }
440
466
  });
441
467
  });
@@ -844,13 +870,13 @@ var SolanaStreamClient = /** @class */ (function (_super) {
844
870
  */
845
871
  SolanaStreamClient.prototype.prepareStreamTransaction = function (recipient, streamParams, solanaExtendedConfig) {
846
872
  return __awaiter(this, void 0, void 0, function () {
847
- var mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, partner, sender, ixs, commitment, recipientPublicKey, mintPublicKey, metadata, _c, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, hash, tx;
848
- var _d;
849
- return __generator(this, function (_e) {
850
- switch (_e.label) {
873
+ var mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, partner, sender, metadataPubKeys, ixs, commitment, recipientPublicKey, mintPublicKey, _c, metadata, metadataPubKey, _d, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, hash, tx;
874
+ var _e;
875
+ return __generator(this, function (_f) {
876
+ switch (_f.label) {
851
877
  case 0:
852
878
  mint = streamParams.tokenId, start = streamParams.start, period = streamParams.period, cliff = streamParams.cliff, canTopup = streamParams.canTopup, cancelableBySender = streamParams.cancelableBySender, cancelableByRecipient = streamParams.cancelableByRecipient, transferableBySender = streamParams.transferableBySender, transferableByRecipient = streamParams.transferableByRecipient, _a = streamParams.automaticWithdrawal, automaticWithdrawal = _a === void 0 ? false : _a, _b = streamParams.withdrawalFrequency, withdrawalFrequency = _b === void 0 ? 0 : _b, partner = streamParams.partner;
853
- sender = solanaExtendedConfig.sender;
879
+ sender = solanaExtendedConfig.sender, metadataPubKeys = solanaExtendedConfig.metadataPubKeys;
854
880
  if (!sender.publicKey) {
855
881
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
856
882
  }
@@ -858,21 +884,21 @@ var SolanaStreamClient = /** @class */ (function (_super) {
858
884
  commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
859
885
  recipientPublicKey = new web3_js_1.PublicKey(recipient.recipient);
860
886
  mintPublicKey = new web3_js_1.PublicKey(mint);
861
- metadata = web3_js_1.Keypair.generate();
862
- _c = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId), 1), escrowTokens = _c[0];
887
+ _c = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _c.metadata, metadataPubKey = _c.metadataPubKey;
888
+ _d = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _d[0];
863
889
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
864
890
  case 1:
865
- senderTokens = _e.sent();
891
+ senderTokens = _f.sent();
866
892
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
867
893
  case 2:
868
- recipientTokens = _e.sent();
894
+ recipientTokens = _f.sent();
869
895
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
870
896
  case 3:
871
- streamflowTreasuryTokens = _e.sent();
897
+ streamflowTreasuryTokens = _f.sent();
872
898
  partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
873
899
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
874
900
  case 4:
875
- partnerTokens = _e.sent();
901
+ partnerTokens = _f.sent();
876
902
  ixs.push((0, instructions_1.createStreamInstruction)({
877
903
  start: new bn_js_1.default(start),
878
904
  depositedAmount: recipient.amount,
@@ -892,7 +918,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
892
918
  sender: sender.publicKey,
893
919
  senderTokens: senderTokens,
894
920
  recipient: new web3_js_1.PublicKey(recipient.recipient),
895
- metadata: metadata.publicKey,
921
+ metadata: metadataPubKey,
896
922
  escrowTokens: escrowTokens,
897
923
  recipientTokens: recipientTokens,
898
924
  streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
@@ -910,18 +936,35 @@ var SolanaStreamClient = /** @class */ (function (_super) {
910
936
  }));
911
937
  return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
912
938
  case 5:
913
- hash = _e.sent();
914
- tx = (_d = new web3_js_1.Transaction({
939
+ hash = _f.sent();
940
+ tx = (_e = new web3_js_1.Transaction({
915
941
  feePayer: sender.publicKey,
916
942
  blockhash: hash.blockhash,
917
943
  lastValidBlockHeight: hash.lastValidBlockHeight,
918
- })).add.apply(_d, __spreadArray([], __read(ixs), false));
919
- tx.partialSign(metadata);
920
- return [2 /*return*/, { tx: tx, metadata: metadata }];
944
+ })).add.apply(_e, __spreadArray([], __read(ixs), false));
945
+ if (metadata) {
946
+ tx.partialSign(metadata);
947
+ }
948
+ return [2 /*return*/, { tx: tx, metadataPubKey: metadataPubKey }];
921
949
  }
922
950
  });
923
951
  });
924
952
  };
953
+ /**
954
+ * Utility function to generate metadata for a Contract or return existing Pubkey
955
+ */
956
+ SolanaStreamClient.prototype.getOrCreateStreamMetadata = function (metadataPubKeys) {
957
+ var metadata;
958
+ var metadataPubKey;
959
+ if (!metadataPubKeys) {
960
+ metadata = web3_js_1.Keypair.generate();
961
+ metadataPubKey = metadata.publicKey;
962
+ }
963
+ else {
964
+ metadataPubKey = metadataPubKeys[0];
965
+ }
966
+ return { metadata: metadata, metadataPubKey: metadataPubKey };
967
+ };
925
968
  return SolanaStreamClient;
926
969
  }(BaseStreamClient_1.BaseStreamClient));
927
970
  exports.default = SolanaStreamClient;
@@ -10,6 +10,7 @@ export interface Account {
10
10
  }
11
11
  export interface ICreateStreamSolanaExt {
12
12
  sender: SignerWalletAdapter | Keypair;
13
+ metadataPubKeys?: PublicKey[];
13
14
  partner?: string | null;
14
15
  isNative?: boolean;
15
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "5.6.7",
3
+ "version": "5.7.1",
4
4
  "description": "JavaScript SDK to interact with Streamflow protocol.",
5
5
  "main": "dist/index.js",
6
6
  "homepage": "https://github.com/streamflow-finance/js-sdk/",
@@ -11,7 +11,7 @@
11
11
  "lint": "eslint .",
12
12
  "prepublishOnly": "npm run lint && npm test && npm run build"
13
13
  },
14
- "gitHead": "79ee3ae9620431f92a248c488a31ee63d2f23259",
14
+ "gitHead": "c28cc0748df1a67de8977faf0286566f74ad1faa",
15
15
  "devDependencies": {
16
16
  "@types/bn.js": "5.1.1",
17
17
  "@types/ethereum-checksum-address": "^0.0.0",