@streamflow/stream 5.10.1 → 5.10.3

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.
@@ -69,7 +69,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
69
69
  /**
70
70
  * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
71
71
  */
72
- private prepareStreamTransaction;
72
+ private prepareStreamInstructions;
73
73
  /**
74
74
  * Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
75
75
  */
@@ -371,11 +371,11 @@ var SolanaStreamClient = /** @class */ (function (_super) {
371
371
  SolanaStreamClient.prototype.createMultiple = function (data, _a) {
372
372
  var sender = _a.sender, metadataPubKeys = _a.metadataPubKeys, _b = _a.isNative, isNative = _b === void 0 ? false : _b;
373
373
  return __awaiter(this, void 0, void 0, function () {
374
- 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;
375
- var _m, e_1, _o;
374
+ var recipients, metadatas, metadataToRecipient, errors, signatures, batch, instructionsBatch, i, recipientData, _c, ixs, metadata, metadataPubKey, commitment, hash, instructionsBatch_1, instructionsBatch_1_1, _d, ixs, metadata, recipient, tx, totalDepositedAmount, nativeInstructions, prepareTransaction, signedBatch, prepareTx, responses, signedBatch_1, signedBatch_1_1, batchTx, _e, _f, _g, _h, e_1_1, batchTransactionsCalls, _j, _k, _l, _m, successes, failures;
375
+ var e_2, _o, _p, _q, e_1, _r;
376
376
  var _this = this;
377
- return __generator(this, function (_p) {
378
- switch (_p.label) {
377
+ return __generator(this, function (_s) {
378
+ switch (_s.label) {
379
379
  case 0:
380
380
  recipients = data.recipients;
381
381
  if (!sender.publicKey) {
@@ -386,45 +386,67 @@ var SolanaStreamClient = /** @class */ (function (_super) {
386
386
  errors = [];
387
387
  signatures = [];
388
388
  batch = [];
389
+ instructionsBatch = [];
389
390
  metadataPubKeys = metadataPubKeys || [];
390
391
  i = 0;
391
- _p.label = 1;
392
+ _s.label = 1;
392
393
  case 1:
393
394
  if (!(i < recipients.length)) return [3 /*break*/, 4];
394
395
  recipientData = recipients[i];
395
- return [4 /*yield*/, this.prepareStreamTransaction(recipientData, data, {
396
+ return [4 /*yield*/, this.prepareStreamInstructions(recipientData, data, {
396
397
  sender: sender,
397
398
  metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
398
399
  })];
399
400
  case 2:
400
- _c = _p.sent(), tx = _c.tx, metadataPubKey = _c.metadataPubKey;
401
+ _c = _s.sent(), ixs = _c.ixs, metadata = _c.metadata, metadataPubKey = _c.metadataPubKey;
401
402
  metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
402
403
  metadatas.push(metadataPubKey.toBase58());
403
- batch.push({ tx: tx, recipient: recipientData.recipient });
404
- _p.label = 3;
404
+ instructionsBatch.push({ ixs: ixs, metadata: metadata, recipient: recipientData.recipient });
405
+ _s.label = 3;
405
406
  case 3:
406
407
  i++;
407
408
  return [3 /*break*/, 1];
408
409
  case 4:
410
+ commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
411
+ return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
412
+ case 5:
413
+ hash = _s.sent();
414
+ try {
415
+ for (instructionsBatch_1 = __values(instructionsBatch), instructionsBatch_1_1 = instructionsBatch_1.next(); !instructionsBatch_1_1.done; instructionsBatch_1_1 = instructionsBatch_1.next()) {
416
+ _d = instructionsBatch_1_1.value, ixs = _d.ixs, metadata = _d.metadata, recipient = _d.recipient;
417
+ tx = (_p = new web3_js_1.Transaction({
418
+ feePayer: sender.publicKey,
419
+ blockhash: hash.blockhash,
420
+ lastValidBlockHeight: hash.lastValidBlockHeight,
421
+ })).add.apply(_p, __spreadArray([], __read(ixs), false));
422
+ if (metadata) {
423
+ tx.partialSign(metadata);
424
+ }
425
+ batch.push({ tx: tx, recipient: recipient });
426
+ }
427
+ }
428
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
429
+ finally {
430
+ try {
431
+ if (instructionsBatch_1_1 && !instructionsBatch_1_1.done && (_o = instructionsBatch_1.return)) _o.call(instructionsBatch_1);
432
+ }
433
+ finally { if (e_2) throw e_2.error; }
434
+ }
409
435
  if (!isNative) return [3 /*break*/, 7];
410
436
  totalDepositedAmount = recipients.reduce(function (acc, recipient) { return recipient.amount.add(acc); }, new bn_js_1.default(0));
411
437
  return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
412
- case 5:
413
- nativeInstructions = _p.sent();
414
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
415
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
416
438
  case 6:
417
- hash = _p.sent();
418
- prepareTransaction = (_m = new web3_js_1.Transaction({
439
+ nativeInstructions = _s.sent();
440
+ prepareTransaction = (_q = new web3_js_1.Transaction({
419
441
  feePayer: sender.publicKey,
420
442
  blockhash: hash.blockhash,
421
443
  lastValidBlockHeight: hash.lastValidBlockHeight,
422
- })).add.apply(_m, __spreadArray([], __read(nativeInstructions), false));
444
+ })).add.apply(_q, __spreadArray([], __read(nativeInstructions), false));
423
445
  batch.push({ tx: prepareTransaction, recipient: sender.publicKey.toBase58() });
424
- _p.label = 7;
446
+ _s.label = 7;
425
447
  case 7: return [4 /*yield*/, (0, utils_1.signAllTransactionWithRecipients)(sender, batch)];
426
448
  case 8:
427
- signedBatch = _p.sent();
449
+ signedBatch = _s.sent();
428
450
  signedBatch.forEach(function (item, index) {
429
451
  item.tx.lastValidBlockHeight = batch[index].tx.lastValidBlockHeight;
430
452
  });
@@ -432,39 +454,39 @@ var SolanaStreamClient = /** @class */ (function (_super) {
432
454
  prepareTx = signedBatch.pop();
433
455
  return [4 /*yield*/, (0, utils_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx)];
434
456
  case 9:
435
- _p.sent();
436
- _p.label = 10;
457
+ _s.sent();
458
+ _s.label = 10;
437
459
  case 10:
438
460
  responses = [];
439
461
  if (!(metadataPubKeys.length > 0)) return [3 /*break*/, 19];
440
- _p.label = 11;
462
+ _s.label = 11;
441
463
  case 11:
442
- _p.trys.push([11, 16, 17, 18]);
464
+ _s.trys.push([11, 16, 17, 18]);
443
465
  signedBatch_1 = __values(signedBatch), signedBatch_1_1 = signedBatch_1.next();
444
- _p.label = 12;
466
+ _s.label = 12;
445
467
  case 12:
446
468
  if (!!signedBatch_1_1.done) return [3 /*break*/, 15];
447
469
  batchTx = signedBatch_1_1.value;
448
- _e = (_d = responses.push).apply;
449
- _f = [responses];
450
- _g = [[]];
470
+ _f = (_e = responses.push).apply;
471
+ _g = [responses];
472
+ _h = [[]];
451
473
  return [4 /*yield*/, Promise.allSettled([
452
474
  (0, utils_1.sendAndConfirmStreamRawTransaction)(this.connection, batchTx),
453
475
  ])];
454
476
  case 13:
455
- _e.apply(_d, _f.concat([__spreadArray.apply(void 0, _g.concat([__read.apply(void 0, [(_p.sent())]), false]))]));
456
- _p.label = 14;
477
+ _f.apply(_e, _g.concat([__spreadArray.apply(void 0, _h.concat([__read.apply(void 0, [(_s.sent())]), false]))]));
478
+ _s.label = 14;
457
479
  case 14:
458
480
  signedBatch_1_1 = signedBatch_1.next();
459
481
  return [3 /*break*/, 12];
460
482
  case 15: return [3 /*break*/, 18];
461
483
  case 16:
462
- e_1_1 = _p.sent();
484
+ e_1_1 = _s.sent();
463
485
  e_1 = { error: e_1_1 };
464
486
  return [3 /*break*/, 18];
465
487
  case 17:
466
488
  try {
467
- if (signedBatch_1_1 && !signedBatch_1_1.done && (_o = signedBatch_1.return)) _o.call(signedBatch_1);
489
+ if (signedBatch_1_1 && !signedBatch_1_1.done && (_r = signedBatch_1.return)) _r.call(signedBatch_1);
468
490
  }
469
491
  finally { if (e_1) throw e_1.error; }
470
492
  return [7 /*endfinally*/];
@@ -473,13 +495,13 @@ var SolanaStreamClient = /** @class */ (function (_super) {
473
495
  batchTransactionsCalls = signedBatch.map(function (el) {
474
496
  return (0, utils_1.sendAndConfirmStreamRawTransaction)(_this.connection, el);
475
497
  });
476
- _j = (_h = responses.push).apply;
477
- _k = [responses];
478
- _l = [[]];
498
+ _k = (_j = responses.push).apply;
499
+ _l = [responses];
500
+ _m = [[]];
479
501
  return [4 /*yield*/, Promise.allSettled(batchTransactionsCalls)];
480
502
  case 20:
481
- _j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(_p.sent())]), false]))]));
482
- _p.label = 21;
503
+ _k.apply(_j, _l.concat([__spreadArray.apply(void 0, _m.concat([__read.apply(void 0, [(_s.sent())]), false]))]));
504
+ _s.label = 21;
483
505
  case 21:
484
506
  successes = responses
485
507
  .filter(function (el) { return el.status === "fulfilled"; })
@@ -905,12 +927,11 @@ var SolanaStreamClient = /** @class */ (function (_super) {
905
927
  /**
906
928
  * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
907
929
  */
908
- SolanaStreamClient.prototype.prepareStreamTransaction = function (recipient, streamParams, solanaExtendedConfig) {
930
+ SolanaStreamClient.prototype.prepareStreamInstructions = function (recipient, streamParams, solanaExtendedConfig) {
909
931
  return __awaiter(this, void 0, void 0, function () {
910
- 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;
911
- var _e;
912
- return __generator(this, function (_f) {
913
- switch (_f.label) {
932
+ var mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, partner, sender, metadataPubKeys, ixs, recipientPublicKey, mintPublicKey, _c, metadata, metadataPubKey, _d, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens;
933
+ return __generator(this, function (_e) {
934
+ switch (_e.label) {
914
935
  case 0:
915
936
  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;
916
937
  sender = solanaExtendedConfig.sender, metadataPubKeys = solanaExtendedConfig.metadataPubKeys;
@@ -918,24 +939,23 @@ var SolanaStreamClient = /** @class */ (function (_super) {
918
939
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
919
940
  }
920
941
  ixs = [];
921
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
922
942
  recipientPublicKey = new web3_js_1.PublicKey(recipient.recipient);
923
943
  mintPublicKey = new web3_js_1.PublicKey(mint);
924
944
  _c = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _c.metadata, metadataPubKey = _c.metadataPubKey;
925
945
  _d = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _d[0];
926
946
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
927
947
  case 1:
928
- senderTokens = _f.sent();
948
+ senderTokens = _e.sent();
929
949
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
930
950
  case 2:
931
- recipientTokens = _f.sent();
951
+ recipientTokens = _e.sent();
932
952
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
933
953
  case 3:
934
- streamflowTreasuryTokens = _f.sent();
954
+ streamflowTreasuryTokens = _e.sent();
935
955
  partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
936
956
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
937
957
  case 4:
938
- partnerTokens = _f.sent();
958
+ partnerTokens = _e.sent();
939
959
  ixs.push((0, instructions_1.createStreamInstruction)({
940
960
  start: new bn_js_1.default(start),
941
961
  depositedAmount: recipient.amount,
@@ -971,18 +991,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
971
991
  withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
972
992
  systemProgram: web3_js_1.SystemProgram.programId,
973
993
  }));
974
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
975
- case 5:
976
- hash = _f.sent();
977
- tx = (_e = new web3_js_1.Transaction({
978
- feePayer: sender.publicKey,
979
- blockhash: hash.blockhash,
980
- lastValidBlockHeight: hash.lastValidBlockHeight,
981
- })).add.apply(_e, __spreadArray([], __read(ixs), false));
982
- if (metadata) {
983
- tx.partialSign(metadata);
984
- }
985
- return [2 /*return*/, { tx: tx, metadataPubKey: metadataPubKey }];
994
+ return [2 /*return*/, { ixs: ixs, metadata: metadata, metadataPubKey: metadataPubKey }];
986
995
  }
987
996
  });
988
997
  });
@@ -7,7 +7,7 @@ var types_1 = require("../common/types");
7
7
  exports.SUI_PROGRAM_IDS = (_a = {},
8
8
  _a[types_1.ICluster.Mainnet] = "0x19007172b22fcfc00c22f1598a9cec7ab52de2b0ea0d111813bc1295a136fc10",
9
9
  _a[types_1.ICluster.Devnet] = "0xf1916c119a6c917d4b36f96ffc0443930745789f3126a716e05a62223c48993a",
10
- _a[types_1.ICluster.Testnet] = "0xf1916c119a6c917d4b36f96ffc0443930745789f3126a716e05a62223c48993a",
10
+ _a[types_1.ICluster.Testnet] = "0xc76590fa8711cd77b9360e00761d80cd09ceb8638e6c8ebcbcd749dcd21a9466",
11
11
  _a[types_1.ICluster.Local] = "0xf1916c119a6c917d4b36f96ffc0443930745789f3126a716e05a62223c48993a",
12
12
  _a);
13
13
  exports.SUI_CONFIG_IDS = (_b = {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "5.10.1",
3
+ "version": "5.10.3",
4
4
  "description": "JavaScript SDK to interact with Streamflow protocol.",
5
5
  "homepage": "https://github.com/streamflow-finance/js-sdk/",
6
6
  "main": "dist/index.js",
@@ -11,7 +11,7 @@
11
11
  "lint": "eslint .",
12
12
  "prepublishOnly": "npm run lint && npm test && npm run build"
13
13
  },
14
- "gitHead": "1cf6009bd62ccc6d141f45caa14ee58ae4a541d9",
14
+ "gitHead": "1e3ac6f4f6f8402aa2130e27514b6f1163790e70",
15
15
  "devDependencies": {
16
16
  "@types/bn.js": "5.1.1",
17
17
  "@types/ethereum-checksum-address": "^0.0.0",