@streamflow/stream 3.0.8 → 3.0.11-dev

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.
@@ -36,6 +36,37 @@ export default class StreamClient {
36
36
  * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
37
37
  */
38
38
  create({ sender, recipient, mint, start, depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: CreateParams): Promise<CreateResponse>;
39
+ /**
40
+ * Creates a new stream/vesting contract using unchecked instruction.
41
+ *
42
+ * Unchecked instruction differes from the regular in:
43
+ * - does not check for initialized associated token account (wallets with no control over their ATA should not be used
44
+ * as sender/recipient/partner or there are risks of funds being locked in the contract)
45
+ * - initialized contract PDA off chain
46
+ *
47
+ * If you are not sure if you should use create or create_unchecked, go for create to be safer.
48
+ *
49
+ * @param {CreateParams} data
50
+ * @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
51
+ * @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
52
+ * @param {string} data.mint - SPL Token mint.
53
+ * @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
54
+ * @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
55
+ * @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
56
+ * @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
57
+ * @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
58
+ * @param {BN} data.amountPerPeriod - Amount unlocked per each period.
59
+ * @param {string} data.name - Stream name/subject.
60
+ * @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
61
+ * @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
62
+ * @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
63
+ * @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
64
+ * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
65
+ * @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
66
+ * @param {number} [data.withdrawalFrequency = 0] - Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
67
+ * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
68
+ */
69
+ createUnchecked({ sender, recipient, mint, start, depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: CreateParams): Promise<CreateResponse>;
39
70
  /**
40
71
  * Creates a new stream/vesting contract.
41
72
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
@@ -96,8 +96,8 @@ var types_1 = require("./types");
96
96
  var utils_1 = require("./utils");
97
97
  var constants_1 = require("./constants");
98
98
  var instructions_1 = require("./instructions");
99
- var common_1 = require("@project-serum/common");
100
99
  var bs58_1 = require("@project-serum/anchor/dist/cjs/utils/bytes/bs58");
100
+ var METADATA_ACC_SIZE = 1104;
101
101
  var StreamClient = /** @class */ (function () {
102
102
  /**
103
103
  * Create Stream instance
@@ -211,15 +211,16 @@ var StreamClient = /** @class */ (function () {
211
211
  commitment = typeof this.commitment == "string"
212
212
  ? this.commitment
213
213
  : this.commitment.commitment;
214
- return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
214
+ return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
215
215
  case 6:
216
216
  hash = _g.sent();
217
217
  tx = (_f = new web3_js_1.Transaction({
218
218
  feePayer: sender.publicKey,
219
- recentBlockhash: hash.blockhash,
219
+ blockhash: hash.blockhash,
220
+ lastValidBlockHeight: hash.lastValidBlockHeight,
220
221
  })).add.apply(_f, __spreadArray([], __read(ixs), false));
221
222
  tx.partialSign(metadata);
222
- return [4 /*yield*/, this.sign(sender, tx)];
223
+ return [4 /*yield*/, this.sign(sender, tx, hash)];
223
224
  case 7:
224
225
  signature = _g.sent();
225
226
  return [2 /*return*/, { ixs: ixs, tx: signature, metadata: metadata }];
@@ -227,6 +228,120 @@ var StreamClient = /** @class */ (function () {
227
228
  });
228
229
  });
229
230
  };
231
+ /**
232
+ * Creates a new stream/vesting contract using unchecked instruction.
233
+ *
234
+ * Unchecked instruction differes from the regular in:
235
+ * - does not check for initialized associated token account (wallets with no control over their ATA should not be used
236
+ * as sender/recipient/partner or there are risks of funds being locked in the contract)
237
+ * - initialized contract PDA off chain
238
+ *
239
+ * If you are not sure if you should use create or create_unchecked, go for create to be safer.
240
+ *
241
+ * @param {CreateParams} data
242
+ * @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
243
+ * @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
244
+ * @param {string} data.mint - SPL Token mint.
245
+ * @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
246
+ * @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
247
+ * @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
248
+ * @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
249
+ * @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
250
+ * @param {BN} data.amountPerPeriod - Amount unlocked per each period.
251
+ * @param {string} data.name - Stream name/subject.
252
+ * @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
253
+ * @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
254
+ * @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
255
+ * @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
256
+ * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
257
+ * @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
258
+ * @param {number} [data.withdrawalFrequency = 0] - Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
259
+ * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
260
+ */
261
+ StreamClient.prototype.createUnchecked = function (_a) {
262
+ var sender = _a.sender, recipient = _a.recipient, mint = _a.mint, start = _a.start, depositedAmount = _a.depositedAmount, 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, _b = _a.automaticWithdrawal, automaticWithdrawal = _b === void 0 ? false : _b, _c = _a.withdrawalFrequency, withdrawalFrequency = _c === void 0 ? 0 : _c, _d = _a.partner, partner = _d === void 0 ? null : _d;
263
+ return __awaiter(this, void 0, void 0, function () {
264
+ var mintPublicKey, recipientPublicKey, metadata, rentToExempt, createMetadataInstruction, _e, escrowTokens, senderTokens, partnerPublicKey, createInstruction, commitment, ixs, hash, tx, signature;
265
+ var _f;
266
+ return __generator(this, function (_g) {
267
+ switch (_g.label) {
268
+ case 0:
269
+ mintPublicKey = new web3_js_1.PublicKey(mint);
270
+ recipientPublicKey = new web3_js_1.PublicKey(recipient);
271
+ metadata = web3_js_1.Keypair.generate();
272
+ return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
273
+ case 1:
274
+ rentToExempt = _g.sent();
275
+ createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
276
+ programId: this.programId,
277
+ space: METADATA_ACC_SIZE,
278
+ lamports: rentToExempt,
279
+ fromPubkey: sender === null || sender === void 0 ? void 0 : sender.publicKey,
280
+ newAccountPubkey: metadata.publicKey,
281
+ });
282
+ return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
283
+ case 2:
284
+ _e = __read.apply(void 0, [_g.sent(), 1]), escrowTokens = _e[0];
285
+ return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
286
+ case 3:
287
+ senderTokens = _g.sent();
288
+ partnerPublicKey = partner
289
+ ? new web3_js_1.PublicKey(partner)
290
+ : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
291
+ createInstruction = (0, instructions_1.createUncheckedStreamInstruction)({
292
+ start: new bn_js_1.default(start),
293
+ depositedAmount: depositedAmount,
294
+ period: new bn_js_1.default(period),
295
+ amountPerPeriod: amountPerPeriod,
296
+ cliff: new bn_js_1.default(cliff),
297
+ cliffAmount: cliffAmount,
298
+ cancelableBySender: cancelableBySender,
299
+ cancelableByRecipient: cancelableByRecipient,
300
+ automaticWithdrawal: automaticWithdrawal,
301
+ transferableBySender: transferableBySender,
302
+ transferableByRecipient: transferableByRecipient,
303
+ canTopup: canTopup,
304
+ name: name,
305
+ withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
306
+ recipient: recipientPublicKey,
307
+ partner: partnerPublicKey,
308
+ }, this.programId, {
309
+ sender: sender.publicKey,
310
+ senderTokens: senderTokens,
311
+ metadata: metadata.publicKey,
312
+ escrowTokens: escrowTokens,
313
+ mint: new web3_js_1.PublicKey(mint),
314
+ feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
315
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
316
+ timelockProgram: this.programId,
317
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
318
+ withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
319
+ systemProgram: web3_js_1.SystemProgram.programId,
320
+ });
321
+ commitment = typeof this.commitment == "string"
322
+ ? this.commitment
323
+ : this.commitment.commitment;
324
+ ixs = [
325
+ createMetadataInstruction,
326
+ createInstruction,
327
+ ];
328
+ return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
329
+ case 4:
330
+ hash = _g.sent();
331
+ tx = (_f = new web3_js_1.Transaction({
332
+ feePayer: sender.publicKey,
333
+ blockhash: hash.blockhash,
334
+ lastValidBlockHeight: hash.lastValidBlockHeight,
335
+ })).add.apply(_f, __spreadArray([], __read(ixs), false));
336
+ tx.partialSign(metadata);
337
+ return [4 /*yield*/, this.sign(sender, tx, hash)];
338
+ case 5:
339
+ signature = _g.sent();
340
+ return [2 /*return*/, { ixs: ixs, tx: signature, metadata: metadata }];
341
+ }
342
+ });
343
+ });
344
+ };
230
345
  /**
231
346
  * Creates a new stream/vesting contract.
232
347
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
@@ -248,42 +363,40 @@ var StreamClient = /** @class */ (function () {
248
363
  */
249
364
  StreamClient.prototype.createMultiple = function (data) {
250
365
  return __awaiter(this, void 0, void 0, function () {
251
- var sender, recipientsData, metadatas, metadataToRecipient, errors, signatures, chunkSize, chunkes, batch, recipientsData_1, recipientsData_1_1, recipientData, _a, tx, metadata, metadataPubKey, e_1_1, i, chunk, chunkes_1, chunkes_1_1, chunk, signed_batch, batchTransactionsCalls, responses, successes, failures, e_2_1;
252
- var e_1, _b, e_2, _c;
366
+ var sender, recipientsData, metadatas, metadataToRecipient, errors, signatures, batch, recipientsData_1, recipientsData_1_1, recipientData, _a, tx, metadata, metadataPubKey, e_1_1, signed_batch, batchTransactionsCalls, responses, successes, failures;
367
+ var e_1, _b;
253
368
  var _this = this;
254
- return __generator(this, function (_d) {
255
- switch (_d.label) {
369
+ return __generator(this, function (_c) {
370
+ switch (_c.label) {
256
371
  case 0:
257
372
  sender = data.sender, recipientsData = data.recipientsData;
258
373
  metadatas = [];
259
374
  metadataToRecipient = {};
260
375
  errors = [];
261
376
  signatures = [];
262
- chunkSize = 100;
263
- chunkes = [];
264
377
  batch = [];
265
- _d.label = 1;
378
+ _c.label = 1;
266
379
  case 1:
267
- _d.trys.push([1, 6, 7, 8]);
380
+ _c.trys.push([1, 6, 7, 8]);
268
381
  recipientsData_1 = __values(recipientsData), recipientsData_1_1 = recipientsData_1.next();
269
- _d.label = 2;
382
+ _c.label = 2;
270
383
  case 2:
271
384
  if (!!recipientsData_1_1.done) return [3 /*break*/, 5];
272
385
  recipientData = recipientsData_1_1.value;
273
386
  return [4 /*yield*/, this.prepareStreamTransaction(recipientData, data)];
274
387
  case 3:
275
- _a = _d.sent(), tx = _a.tx, metadata = _a.metadata;
388
+ _a = _c.sent(), tx = _a.tx, metadata = _a.metadata;
276
389
  metadataPubKey = metadata.publicKey.toBase58();
277
390
  metadataToRecipient[metadataPubKey] = recipientData;
278
391
  metadatas.push(metadata);
279
392
  batch.push({ tx: tx, recipient: recipientData.recipient });
280
- _d.label = 4;
393
+ _c.label = 4;
281
394
  case 4:
282
395
  recipientsData_1_1 = recipientsData_1.next();
283
396
  return [3 /*break*/, 2];
284
397
  case 5: return [3 /*break*/, 8];
285
398
  case 6:
286
- e_1_1 = _d.sent();
399
+ e_1_1 = _c.sent();
287
400
  e_1 = { error: e_1_1 };
288
401
  return [3 /*break*/, 8];
289
402
  case 7:
@@ -292,28 +405,15 @@ var StreamClient = /** @class */ (function () {
292
405
  }
293
406
  finally { if (e_1) throw e_1.error; }
294
407
  return [7 /*endfinally*/];
295
- case 8:
296
- for (i = 0; i < batch.length; i += chunkSize) {
297
- chunk = batch.slice(i, i + chunkSize);
298
- chunkes.push(chunk);
299
- }
300
- _d.label = 9;
408
+ case 8: return [4 /*yield*/, signAllTransactionWithRecipients(sender, batch)];
301
409
  case 9:
302
- _d.trys.push([9, 16, 17, 18]);
303
- chunkes_1 = __values(chunkes), chunkes_1_1 = chunkes_1.next();
304
- _d.label = 10;
305
- case 10:
306
- if (!!chunkes_1_1.done) return [3 /*break*/, 15];
307
- chunk = chunkes_1_1.value;
308
- return [4 /*yield*/, signAllTransactionWithRecipients(sender, chunk)];
309
- case 11:
310
- signed_batch = _d.sent();
410
+ signed_batch = _c.sent();
311
411
  batchTransactionsCalls = signed_batch.map(function (el) {
312
412
  return sendAndConfirmStreamRawTransaction(_this.connection, el);
313
413
  });
314
414
  return [4 /*yield*/, Promise.allSettled(batchTransactionsCalls)];
315
- case 12:
316
- responses = _d.sent();
415
+ case 10:
416
+ responses = _c.sent();
317
417
  successes = responses
318
418
  .filter(function (el) {
319
419
  return el.status === "fulfilled";
@@ -324,25 +424,7 @@ var StreamClient = /** @class */ (function () {
324
424
  .filter(function (el) { return el.status === "rejected"; })
325
425
  .map(function (el) { return el.reason; });
326
426
  errors.push.apply(errors, __spreadArray([], __read(failures), false));
327
- return [4 /*yield*/, (0, common_1.sleep)(100)];
328
- case 13:
329
- _d.sent();
330
- _d.label = 14;
331
- case 14:
332
- chunkes_1_1 = chunkes_1.next();
333
- return [3 /*break*/, 10];
334
- case 15: return [3 /*break*/, 18];
335
- case 16:
336
- e_2_1 = _d.sent();
337
- e_2 = { error: e_2_1 };
338
- return [3 /*break*/, 18];
339
- case 17:
340
- try {
341
- if (chunkes_1_1 && !chunkes_1_1.done && (_c = chunkes_1.return)) _c.call(chunkes_1);
342
- }
343
- finally { if (e_2) throw e_2.error; }
344
- return [7 /*endfinally*/];
345
- case 18: return [2 /*return*/, { txs: signatures, metadatas: metadatas, metadataToRecipient: metadataToRecipient, errors: errors }];
427
+ return [2 /*return*/, { txs: signatures, metadatas: metadatas, metadataToRecipient: metadataToRecipient, errors: errors }];
346
428
  }
347
429
  });
348
430
  });
@@ -393,14 +475,15 @@ var StreamClient = /** @class */ (function () {
393
475
  commitment = typeof this.commitment == "string"
394
476
  ? this.commitment
395
477
  : this.commitment.commitment;
396
- return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
478
+ return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
397
479
  case 4:
398
480
  hash = _c.sent();
399
481
  tx = (_b = new web3_js_1.Transaction({
400
482
  feePayer: invoker.publicKey,
401
- recentBlockhash: hash.blockhash,
483
+ blockhash: hash.blockhash,
484
+ lastValidBlockHeight: hash.lastValidBlockHeight,
402
485
  })).add.apply(_b, __spreadArray([], __read(ixs), false));
403
- return [4 /*yield*/, this.sign(invoker, tx)];
486
+ return [4 /*yield*/, this.sign(invoker, tx, hash)];
404
487
  case 5:
405
488
  signature = _c.sent();
406
489
  return [2 /*return*/, { ixs: ixs, tx: signature }];
@@ -455,14 +538,15 @@ var StreamClient = /** @class */ (function () {
455
538
  commitment = typeof this.commitment == "string"
456
539
  ? this.commitment
457
540
  : this.commitment.commitment;
458
- return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
541
+ return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
459
542
  case 4:
460
543
  hash = _c.sent();
461
544
  tx = (_b = new web3_js_1.Transaction({
462
545
  feePayer: invoker.publicKey,
463
- recentBlockhash: hash.blockhash,
546
+ blockhash: hash.blockhash,
547
+ lastValidBlockHeight: hash.lastValidBlockHeight,
464
548
  })).add.apply(_b, __spreadArray([], __read(ixs), false));
465
- return [4 /*yield*/, this.sign(invoker, tx)];
549
+ return [4 /*yield*/, this.sign(invoker, tx, hash)];
466
550
  case 5:
467
551
  signature = _c.sent();
468
552
  return [2 /*return*/, { ixs: ixs, tx: signature }];
@@ -513,14 +597,15 @@ var StreamClient = /** @class */ (function () {
513
597
  commitment = typeof this.commitment == "string"
514
598
  ? this.commitment
515
599
  : this.commitment.commitment;
516
- return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
600
+ return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
517
601
  case 3:
518
602
  hash = _c.sent();
519
603
  tx = (_b = new web3_js_1.Transaction({
520
604
  feePayer: invoker.publicKey,
521
- recentBlockhash: hash.blockhash,
605
+ blockhash: hash.blockhash,
606
+ lastValidBlockHeight: hash.lastValidBlockHeight,
522
607
  })).add.apply(_b, __spreadArray([], __read(ixs), false));
523
- return [4 /*yield*/, this.sign(invoker, tx)];
608
+ return [4 /*yield*/, this.sign(invoker, tx, hash)];
524
609
  case 4:
525
610
  signature = _c.sent();
526
611
  return [2 /*return*/, { ixs: ixs, tx: signature }];
@@ -575,14 +660,15 @@ var StreamClient = /** @class */ (function () {
575
660
  commitment = typeof this.commitment == "string"
576
661
  ? this.commitment
577
662
  : this.commitment.commitment;
578
- return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
663
+ return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
579
664
  case 4:
580
665
  hash = _d.sent();
581
666
  tx = (_c = new web3_js_1.Transaction({
582
667
  feePayer: invoker.publicKey,
583
- recentBlockhash: hash.blockhash,
668
+ blockhash: hash.blockhash,
669
+ lastValidBlockHeight: hash.lastValidBlockHeight,
584
670
  })).add.apply(_c, __spreadArray([], __read(ixs), false));
585
- return [4 /*yield*/, this.sign(invoker, tx)];
671
+ return [4 /*yield*/, this.sign(invoker, tx, hash)];
586
672
  case 5:
587
673
  signature = _d.sent();
588
674
  return [2 /*return*/, { ixs: ixs, tx: signature }];
@@ -664,24 +750,30 @@ var StreamClient = /** @class */ (function () {
664
750
  });
665
751
  });
666
752
  };
667
- StreamClient.prototype.sign = function (invoker, tx) {
753
+ StreamClient.prototype.sign = function (invoker, tx, hash) {
668
754
  return __awaiter(this, void 0, void 0, function () {
669
- var rawTx, signature;
755
+ var rawTx, confirmationStrategy, signature;
670
756
  return __generator(this, function (_a) {
671
757
  switch (_a.label) {
672
758
  case 0:
673
- if (!(invoker instanceof web3_js_1.Keypair)) return [3 /*break*/, 1];
674
- tx.partialSign(invoker);
675
- return [3 /*break*/, 3];
676
- case 1:
677
- if (!(invoker === null || invoker === void 0 ? void 0 : invoker.signTransaction)) return [3 /*break*/, 3];
759
+ if (!isAnchorWallet(invoker)) return [3 /*break*/, 2];
678
760
  return [4 /*yield*/, invoker.signTransaction(tx)];
679
- case 2:
761
+ case 1:
680
762
  _a.sent();
763
+ return [3 /*break*/, 3];
764
+ case 2:
765
+ tx.partialSign(invoker);
681
766
  _a.label = 3;
682
767
  case 3:
683
768
  rawTx = tx.serialize();
684
- return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, rawTx)];
769
+ if (!hash.lastValidBlockHeight || !tx.signature || !hash.blockhash)
770
+ throw Error("Error with transaction parameters.");
771
+ confirmationStrategy = {
772
+ lastValidBlockHeight: hash.lastValidBlockHeight,
773
+ signature: (0, bs58_1.encode)(tx.signature),
774
+ blockhash: hash.blockhash,
775
+ };
776
+ return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, rawTx, confirmationStrategy)];
685
777
  case 4:
686
778
  signature = _a.sent();
687
779
  return [2 /*return*/, signature];
@@ -810,51 +902,28 @@ function isAnchorWallet(wallet) {
810
902
  }
811
903
  function signAllTransactionWithRecipients(sender, batch) {
812
904
  return __awaiter(this, void 0, void 0, function () {
813
- var signed_batch, isKeypair, isWallet, recipientToBlockhashMap_1, batch_1, batch_1_1, item, txs;
814
- var e_3, _a;
815
- return __generator(this, function (_b) {
816
- switch (_b.label) {
905
+ var signed_batch, isKeypair, isWallet;
906
+ return __generator(this, function (_a) {
907
+ switch (_a.label) {
817
908
  case 0:
818
909
  signed_batch = [];
819
910
  isKeypair = sender instanceof web3_js_1.Keypair;
820
911
  isWallet = isAnchorWallet(sender);
821
912
  if (!isKeypair && !isWallet)
822
913
  return [2 /*return*/, signed_batch];
823
- if (isKeypair) {
824
- signed_batch = batch.map(function (t) {
825
- t.tx.partialSign(sender);
826
- return { tx: t.tx, recipient: t.recipient };
827
- });
828
- }
829
- if (!isWallet) return [3 /*break*/, 2];
830
- recipientToBlockhashMap_1 = new Map();
831
- try {
832
- for (batch_1 = __values(batch), batch_1_1 = batch_1.next(); !batch_1_1.done; batch_1_1 = batch_1.next()) {
833
- item = batch_1_1.value;
834
- recipientToBlockhashMap_1.set(item.tx.recentBlockhash, item);
835
- }
836
- }
837
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
838
- finally {
839
- try {
840
- if (batch_1_1 && !batch_1_1.done && (_a = batch_1.return)) _a.call(batch_1);
841
- }
842
- finally { if (e_3) throw e_3.error; }
843
- }
844
- return [4 /*yield*/, sender.signAllTransactions(batch.map(function (t) { return t.tx; }))];
845
- case 1:
846
- txs = _b.sent();
847
- txs.map(function (tx) {
848
- var item = recipientToBlockhashMap_1.get(tx.recentBlockhash);
849
- if (item) {
850
- signed_batch.push({
851
- tx: tx,
852
- recipient: item.recipient,
853
- });
854
- }
914
+ if (!isKeypair) return [3 /*break*/, 1];
915
+ batch.map(function (t) {
916
+ t.tx.partialSign(sender);
917
+ return { tx: t.tx, recipient: t.recipient };
855
918
  });
856
- _b.label = 2;
857
- case 2: return [2 /*return*/, signed_batch];
919
+ return [3 /*break*/, 3];
920
+ case 1:
921
+ if (!isWallet) return [3 /*break*/, 3];
922
+ return [4 /*yield*/, sender.signAllTransactions(batch.map(function (t) { return t.tx; }))];
923
+ case 2:
924
+ _a.sent();
925
+ _a.label = 3;
926
+ case 3: return [2 /*return*/, batch];
858
927
  }
859
928
  });
860
929
  });
@@ -37,6 +37,38 @@ interface CreateStreamAccounts {
37
37
  systemProgram: PublicKey;
38
38
  }
39
39
  export declare const createStreamInstruction: (data: CreateStreamData, programId: PublicKey, accounts: CreateStreamAccounts) => TransactionInstruction;
40
+ interface CreateUncheckedStreamData {
41
+ start: BN;
42
+ depositedAmount: BN;
43
+ period: BN;
44
+ amountPerPeriod: BN;
45
+ cliff: BN;
46
+ cliffAmount: BN;
47
+ cancelableBySender: boolean;
48
+ cancelableByRecipient: boolean;
49
+ automaticWithdrawal: boolean;
50
+ transferableBySender: boolean;
51
+ transferableByRecipient: boolean;
52
+ canTopup: boolean;
53
+ name: string;
54
+ withdrawFrequency: BN;
55
+ recipient: PublicKey;
56
+ partner: PublicKey;
57
+ }
58
+ interface CreateUncheckedStreamAccounts {
59
+ sender: PublicKey;
60
+ senderTokens: PublicKey;
61
+ metadata: PublicKey;
62
+ escrowTokens: PublicKey;
63
+ mint: PublicKey;
64
+ feeOracle: PublicKey;
65
+ rent: PublicKey;
66
+ timelockProgram: PublicKey;
67
+ tokenProgram: PublicKey;
68
+ withdrawor: PublicKey;
69
+ systemProgram: PublicKey;
70
+ }
71
+ export declare const createUncheckedStreamInstruction: (data: CreateUncheckedStreamData, programId: PublicKey, accounts: CreateUncheckedStreamAccounts) => TransactionInstruction;
40
72
  interface WithdrawAccounts {
41
73
  authority: PublicKey;
42
74
  recipient: PublicKey;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.withdrawStreamInstruction = exports.createStreamInstruction = void 0;
26
+ exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
27
27
  var buffer_1 = require("buffer");
28
28
  var web3_js_1 = require("@solana/web3.js");
29
29
  var js_sha256_1 = require("js-sha256");
@@ -94,6 +94,57 @@ var createStreamInstruction = function (data, programId, accounts) {
94
94
  });
95
95
  };
96
96
  exports.createStreamInstruction = createStreamInstruction;
97
+ var createUncheckedStreamInstruction = function (data, programId, accounts) {
98
+ var keys = [
99
+ { pubkey: accounts.sender, isSigner: true, isWritable: true },
100
+ { pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
101
+ { pubkey: accounts.metadata, isSigner: false, isWritable: true },
102
+ { pubkey: accounts.escrowTokens, isSigner: false, isWritable: true },
103
+ { pubkey: accounts.withdrawor, isSigner: false, isWritable: true },
104
+ { pubkey: accounts.mint, isSigner: false, isWritable: false },
105
+ { pubkey: accounts.feeOracle, isSigner: false, isWritable: false },
106
+ { pubkey: accounts.rent, isSigner: false, isWritable: false },
107
+ { pubkey: accounts.timelockProgram, isSigner: false, isWritable: false },
108
+ { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
109
+ { pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
110
+ ];
111
+ var bufferData = buffer_1.Buffer.alloc(Layout.createUncheckedStreamLayout.span);
112
+ var encodedUIntArray = new TextEncoder().encode(data.name);
113
+ var streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
114
+ var decodedData = {
115
+ start_time: data.start.toArrayLike(buffer_1.Buffer, "le", 8),
116
+ net_amount_deposited: data.depositedAmount.toArrayLike(buffer_1.Buffer, "le", 8),
117
+ period: data.period.toArrayLike(buffer_1.Buffer, "le", 8),
118
+ amount_per_period: data.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8),
119
+ cliff: data.cliff.toArrayLike(buffer_1.Buffer, "le", 8),
120
+ cliff_amount: data.cliffAmount.toArrayLike(buffer_1.Buffer, "le", 8),
121
+ cancelable_by_sender: data.cancelableBySender,
122
+ cancelable_by_recipient: data.cancelableByRecipient,
123
+ automatic_withdrawal: data.automaticWithdrawal,
124
+ transferable_by_sender: data.transferableBySender,
125
+ transferable_by_recipient: data.transferableByRecipient,
126
+ can_topup: data.canTopup,
127
+ stream_name: streamNameBuffer,
128
+ withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8),
129
+ recipient: data.recipient.toBuffer(),
130
+ partner: data.partner.toBuffer(),
131
+ pausable: buffer_1.Buffer.alloc(1),
132
+ can_update_rate: buffer_1.Buffer.alloc(1),
133
+ };
134
+ var encodeLength = Layout.createUncheckedStreamLayout.encode(decodedData, bufferData);
135
+ bufferData = bufferData.slice(0, encodeLength);
136
+ bufferData = buffer_1.Buffer.concat([
137
+ buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:create_unchecked")).slice(0, 8),
138
+ bufferData,
139
+ buffer_1.Buffer.alloc(10),
140
+ ]);
141
+ return new web3_js_1.TransactionInstruction({
142
+ keys: keys,
143
+ programId: programId,
144
+ data: bufferData,
145
+ });
146
+ };
147
+ exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
97
148
  var withdrawStreamInstruction = function (amount, programId, _a) {
98
149
  var authority = _a.authority, recipient = _a.recipient, recipientTokens = _a.recipientTokens, metadata = _a.metadata, escrowTokens = _a.escrowTokens, streamflowTreasury = _a.streamflowTreasury, streamflowTreasuryTokens = _a.streamflowTreasuryTokens, partner = _a.partner, partnerTokens = _a.partnerTokens, mint = _a.mint, tokenProgram = _a.tokenProgram;
99
150
  var keys = [
package/dist/layout.d.ts CHANGED
@@ -7,6 +7,10 @@ export declare const streamLayout: typeof BufferLayout.Structure;
7
7
  * Create stream instruction layout
8
8
  */
9
9
  export declare const createStreamLayout: typeof BufferLayout.Structure;
10
+ /**
11
+ * Create unchecked stream instruction layout
12
+ */
13
+ export declare const createUncheckedStreamLayout: typeof BufferLayout.Structure;
10
14
  /**
11
15
  * Withdraw stream instruction layout
12
16
  */
package/dist/layout.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.topupStreamLayout = exports.withdrawStreamLayout = exports.createStreamLayout = exports.streamLayout = void 0;
3
+ exports.topupStreamLayout = exports.withdrawStreamLayout = exports.createUncheckedStreamLayout = exports.createStreamLayout = exports.streamLayout = void 0;
4
4
  var BufferLayout = require("buffer-layout");
5
5
  /**
6
6
  * Stream layout
@@ -63,6 +63,29 @@ exports.createStreamLayout = BufferLayout.struct([
63
63
  BufferLayout.blob(64, "stream_name"),
64
64
  BufferLayout.blob(8, "withdraw_frequency"),
65
65
  ]);
66
+ /**
67
+ * Create unchecked stream instruction layout
68
+ */
69
+ exports.createUncheckedStreamLayout = BufferLayout.struct([
70
+ BufferLayout.blob(8, "start_time"),
71
+ BufferLayout.blob(8, "net_amount_deposited"),
72
+ BufferLayout.blob(8, "period"),
73
+ BufferLayout.blob(8, "amount_per_period"),
74
+ BufferLayout.blob(8, "cliff"),
75
+ BufferLayout.blob(8, "cliff_amount"),
76
+ BufferLayout.u8("cancelable_by_sender"),
77
+ BufferLayout.u8("cancelable_by_recipient"),
78
+ BufferLayout.u8("automatic_withdrawal"),
79
+ BufferLayout.u8("transferable_by_sender"),
80
+ BufferLayout.u8("transferable_by_recipient"),
81
+ BufferLayout.u8("can_topup"),
82
+ BufferLayout.blob(64, "stream_name"),
83
+ BufferLayout.blob(8, "withdraw_frequency"),
84
+ BufferLayout.blob(32, "recipient"),
85
+ BufferLayout.blob(32, "partner"),
86
+ BufferLayout.u8("pausable"),
87
+ BufferLayout.u8("can_update_rate"),
88
+ ]);
66
89
  /**
67
90
  * Withdraw stream instruction layout
68
91
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "3.0.8",
3
+ "version": "3.0.11-dev",
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/",