@streamflow/stream 3.0.6 → 3.0.9

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.
package/dist/Stream.js CHANGED
@@ -410,7 +410,7 @@ var Stream = /** @class */ (function () {
410
410
  if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
411
411
  throw new Error("Couldn't get account info.");
412
412
  }
413
- return [2 /*return*/, (0, utils_1.formatDecodedStream)((0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data))];
413
+ return [2 /*return*/, new types_1.Contract((0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data))];
414
414
  }
415
415
  });
416
416
  });
@@ -454,7 +454,7 @@ var Stream = /** @class */ (function () {
454
454
  streams = {};
455
455
  accounts.forEach(function (account) {
456
456
  var _a;
457
- var decoded = (0, utils_1.formatDecodedStream)((0, utils_1.decodeStream)(account.account.data));
457
+ var decoded = new types_1.Contract((0, utils_1.decodeStream)(account.account.data));
458
458
  streams = __assign(__assign({}, streams), (_a = {}, _a[account.pubkey.toBase58()] = decoded, _a));
459
459
  });
460
460
  sortedStreams = Object.entries(streams).sort(function (_a, _b) {
@@ -97,6 +97,7 @@ var utils_1 = require("./utils");
97
97
  var constants_1 = require("./constants");
98
98
  var instructions_1 = require("./instructions");
99
99
  var common_1 = require("@project-serum/common");
100
+ var bs58_1 = require("@project-serum/anchor/dist/cjs/utils/bytes/bs58");
100
101
  var StreamClient = /** @class */ (function () {
101
102
  /**
102
103
  * Create Stream instance
@@ -210,15 +211,16 @@ var StreamClient = /** @class */ (function () {
210
211
  commitment = typeof this.commitment == "string"
211
212
  ? this.commitment
212
213
  : this.commitment.commitment;
213
- return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
214
+ return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
214
215
  case 6:
215
216
  hash = _g.sent();
216
217
  tx = (_f = new web3_js_1.Transaction({
217
218
  feePayer: sender.publicKey,
218
- recentBlockhash: hash.blockhash,
219
+ blockhash: hash.blockhash,
220
+ lastValidBlockHeight: hash.lastValidBlockHeight,
219
221
  })).add.apply(_f, __spreadArray([], __read(ixs), false));
220
222
  tx.partialSign(metadata);
221
- return [4 /*yield*/, this.sign(sender, tx)];
223
+ return [4 /*yield*/, this.sign(sender, tx, hash)];
222
224
  case 7:
223
225
  signature = _g.sent();
224
226
  return [2 /*return*/, { ixs: ixs, tx: signature, metadata: metadata }];
@@ -247,8 +249,8 @@ var StreamClient = /** @class */ (function () {
247
249
  */
248
250
  StreamClient.prototype.createMultiple = function (data) {
249
251
  return __awaiter(this, void 0, void 0, function () {
250
- var sender, recipientsData, metadatas, metadataToRecipient, errors, signatures, chunkSize, chunkes, i, chunk, chunkes_1, chunkes_1_1, chunk, batch, chunk_1, chunk_1_1, recipientData, _a, tx, metadata, metadataPubKey, e_1_1, signed_batch, batchTransactionsCalls, responses, successes, failures, e_2_1;
251
- var e_2, _b, e_1, _c;
252
+ 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;
253
+ var e_1, _b, e_2, _c;
252
254
  var _this = this;
253
255
  return __generator(this, function (_d) {
254
256
  switch (_d.label) {
@@ -258,52 +260,53 @@ var StreamClient = /** @class */ (function () {
258
260
  metadataToRecipient = {};
259
261
  errors = [];
260
262
  signatures = [];
261
- chunkSize = 10;
263
+ chunkSize = 100;
262
264
  chunkes = [];
263
- for (i = 0; i < recipientsData.length; i += chunkSize) {
264
- chunk = recipientsData.slice(i, i + chunkSize);
265
- chunkes.push(chunk);
266
- }
265
+ batch = [];
267
266
  _d.label = 1;
268
267
  case 1:
269
- _d.trys.push([1, 16, 17, 18]);
270
- chunkes_1 = __values(chunkes), chunkes_1_1 = chunkes_1.next();
268
+ _d.trys.push([1, 6, 7, 8]);
269
+ recipientsData_1 = __values(recipientsData), recipientsData_1_1 = recipientsData_1.next();
271
270
  _d.label = 2;
272
271
  case 2:
273
- if (!!chunkes_1_1.done) return [3 /*break*/, 15];
274
- chunk = chunkes_1_1.value;
275
- batch = [];
276
- _d.label = 3;
277
- case 3:
278
- _d.trys.push([3, 8, 9, 10]);
279
- chunk_1 = (e_1 = void 0, __values(chunk)), chunk_1_1 = chunk_1.next();
280
- _d.label = 4;
281
- case 4:
282
- if (!!chunk_1_1.done) return [3 /*break*/, 7];
283
- recipientData = chunk_1_1.value;
272
+ if (!!recipientsData_1_1.done) return [3 /*break*/, 5];
273
+ recipientData = recipientsData_1_1.value;
284
274
  return [4 /*yield*/, this.prepareStreamTransaction(recipientData, data)];
285
- case 5:
275
+ case 3:
286
276
  _a = _d.sent(), tx = _a.tx, metadata = _a.metadata;
287
277
  metadataPubKey = metadata.publicKey.toBase58();
288
278
  metadataToRecipient[metadataPubKey] = recipientData;
289
279
  metadatas.push(metadata);
290
280
  batch.push({ tx: tx, recipient: recipientData.recipient });
291
- _d.label = 6;
281
+ _d.label = 4;
282
+ case 4:
283
+ recipientsData_1_1 = recipientsData_1.next();
284
+ return [3 /*break*/, 2];
285
+ case 5: return [3 /*break*/, 8];
292
286
  case 6:
293
- chunk_1_1 = chunk_1.next();
294
- return [3 /*break*/, 4];
295
- case 7: return [3 /*break*/, 10];
296
- case 8:
297
287
  e_1_1 = _d.sent();
298
288
  e_1 = { error: e_1_1 };
299
- return [3 /*break*/, 10];
300
- case 9:
289
+ return [3 /*break*/, 8];
290
+ case 7:
301
291
  try {
302
- if (chunk_1_1 && !chunk_1_1.done && (_c = chunk_1.return)) _c.call(chunk_1);
292
+ if (recipientsData_1_1 && !recipientsData_1_1.done && (_b = recipientsData_1.return)) _b.call(recipientsData_1);
303
293
  }
304
294
  finally { if (e_1) throw e_1.error; }
305
295
  return [7 /*endfinally*/];
306
- case 10: return [4 /*yield*/, signAllTransactionWithRecipients(sender, batch)];
296
+ case 8:
297
+ for (i = 0; i < batch.length; i += chunkSize) {
298
+ chunk = batch.slice(i, i + chunkSize);
299
+ chunkes.push(chunk);
300
+ }
301
+ _d.label = 9;
302
+ case 9:
303
+ _d.trys.push([9, 16, 17, 18]);
304
+ chunkes_1 = __values(chunkes), chunkes_1_1 = chunkes_1.next();
305
+ _d.label = 10;
306
+ case 10:
307
+ if (!!chunkes_1_1.done) return [3 /*break*/, 15];
308
+ chunk = chunkes_1_1.value;
309
+ return [4 /*yield*/, signAllTransactionWithRecipients(sender, chunk)];
307
310
  case 11:
308
311
  signed_batch = _d.sent();
309
312
  batchTransactionsCalls = signed_batch.map(function (el) {
@@ -328,7 +331,7 @@ var StreamClient = /** @class */ (function () {
328
331
  _d.label = 14;
329
332
  case 14:
330
333
  chunkes_1_1 = chunkes_1.next();
331
- return [3 /*break*/, 2];
334
+ return [3 /*break*/, 10];
332
335
  case 15: return [3 /*break*/, 18];
333
336
  case 16:
334
337
  e_2_1 = _d.sent();
@@ -336,7 +339,7 @@ var StreamClient = /** @class */ (function () {
336
339
  return [3 /*break*/, 18];
337
340
  case 17:
338
341
  try {
339
- if (chunkes_1_1 && !chunkes_1_1.done && (_b = chunkes_1.return)) _b.call(chunkes_1);
342
+ if (chunkes_1_1 && !chunkes_1_1.done && (_c = chunkes_1.return)) _c.call(chunkes_1);
340
343
  }
341
344
  finally { if (e_2) throw e_2.error; }
342
345
  return [7 /*endfinally*/];
@@ -391,14 +394,15 @@ var StreamClient = /** @class */ (function () {
391
394
  commitment = typeof this.commitment == "string"
392
395
  ? this.commitment
393
396
  : this.commitment.commitment;
394
- return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
397
+ return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
395
398
  case 4:
396
399
  hash = _c.sent();
397
400
  tx = (_b = new web3_js_1.Transaction({
398
401
  feePayer: invoker.publicKey,
399
- recentBlockhash: hash.blockhash,
402
+ blockhash: hash.blockhash,
403
+ lastValidBlockHeight: hash.lastValidBlockHeight,
400
404
  })).add.apply(_b, __spreadArray([], __read(ixs), false));
401
- return [4 /*yield*/, this.sign(invoker, tx)];
405
+ return [4 /*yield*/, this.sign(invoker, tx, hash)];
402
406
  case 5:
403
407
  signature = _c.sent();
404
408
  return [2 /*return*/, { ixs: ixs, tx: signature }];
@@ -453,14 +457,15 @@ var StreamClient = /** @class */ (function () {
453
457
  commitment = typeof this.commitment == "string"
454
458
  ? this.commitment
455
459
  : this.commitment.commitment;
456
- return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
460
+ return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
457
461
  case 4:
458
462
  hash = _c.sent();
459
463
  tx = (_b = new web3_js_1.Transaction({
460
464
  feePayer: invoker.publicKey,
461
- recentBlockhash: hash.blockhash,
465
+ blockhash: hash.blockhash,
466
+ lastValidBlockHeight: hash.lastValidBlockHeight,
462
467
  })).add.apply(_b, __spreadArray([], __read(ixs), false));
463
- return [4 /*yield*/, this.sign(invoker, tx)];
468
+ return [4 /*yield*/, this.sign(invoker, tx, hash)];
464
469
  case 5:
465
470
  signature = _c.sent();
466
471
  return [2 /*return*/, { ixs: ixs, tx: signature }];
@@ -511,14 +516,15 @@ var StreamClient = /** @class */ (function () {
511
516
  commitment = typeof this.commitment == "string"
512
517
  ? this.commitment
513
518
  : this.commitment.commitment;
514
- return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
519
+ return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
515
520
  case 3:
516
521
  hash = _c.sent();
517
522
  tx = (_b = new web3_js_1.Transaction({
518
523
  feePayer: invoker.publicKey,
519
- recentBlockhash: hash.blockhash,
524
+ blockhash: hash.blockhash,
525
+ lastValidBlockHeight: hash.lastValidBlockHeight,
520
526
  })).add.apply(_b, __spreadArray([], __read(ixs), false));
521
- return [4 /*yield*/, this.sign(invoker, tx)];
527
+ return [4 /*yield*/, this.sign(invoker, tx, hash)];
522
528
  case 4:
523
529
  signature = _c.sent();
524
530
  return [2 /*return*/, { ixs: ixs, tx: signature }];
@@ -573,14 +579,15 @@ var StreamClient = /** @class */ (function () {
573
579
  commitment = typeof this.commitment == "string"
574
580
  ? this.commitment
575
581
  : this.commitment.commitment;
576
- return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
582
+ return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
577
583
  case 4:
578
584
  hash = _d.sent();
579
585
  tx = (_c = new web3_js_1.Transaction({
580
586
  feePayer: invoker.publicKey,
581
- recentBlockhash: hash.blockhash,
587
+ blockhash: hash.blockhash,
588
+ lastValidBlockHeight: hash.lastValidBlockHeight,
582
589
  })).add.apply(_c, __spreadArray([], __read(ixs), false));
583
- return [4 /*yield*/, this.sign(invoker, tx)];
590
+ return [4 /*yield*/, this.sign(invoker, tx, hash)];
584
591
  case 5:
585
592
  signature = _d.sent();
586
593
  return [2 /*return*/, { ixs: ixs, tx: signature }];
@@ -603,7 +610,7 @@ var StreamClient = /** @class */ (function () {
603
610
  if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
604
611
  throw new Error("Couldn't get account info.");
605
612
  }
606
- return [2 /*return*/, (0, utils_1.formatDecodedStream)((0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data))];
613
+ return [2 /*return*/, new types_1.Contract((0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data))];
607
614
  }
608
615
  });
609
616
  });
@@ -645,7 +652,7 @@ var StreamClient = /** @class */ (function () {
645
652
  streams = {};
646
653
  accounts.forEach(function (account) {
647
654
  var _a;
648
- var decoded = (0, utils_1.formatDecodedStream)((0, utils_1.decodeStream)(account.account.data));
655
+ var decoded = new types_1.Contract((0, utils_1.decodeStream)(account.account.data));
649
656
  streams = __assign(__assign({}, streams), (_a = {}, _a[account.pubkey.toBase58()] = decoded, _a));
650
657
  });
651
658
  sortedStreams = Object.entries(streams).sort(function (_a, _b) {
@@ -662,24 +669,30 @@ var StreamClient = /** @class */ (function () {
662
669
  });
663
670
  });
664
671
  };
665
- StreamClient.prototype.sign = function (invoker, tx) {
672
+ StreamClient.prototype.sign = function (invoker, tx, hash) {
666
673
  return __awaiter(this, void 0, void 0, function () {
667
- var rawTx, signature;
674
+ var rawTx, confirmationStrategy, signature;
668
675
  return __generator(this, function (_a) {
669
676
  switch (_a.label) {
670
677
  case 0:
671
- if (!(invoker instanceof web3_js_1.Keypair)) return [3 /*break*/, 1];
672
- tx.partialSign(invoker);
673
- return [3 /*break*/, 3];
674
- case 1:
675
- if (!(invoker === null || invoker === void 0 ? void 0 : invoker.signTransaction)) return [3 /*break*/, 3];
678
+ if (!isAnchorWallet(invoker)) return [3 /*break*/, 2];
676
679
  return [4 /*yield*/, invoker.signTransaction(tx)];
677
- case 2:
680
+ case 1:
678
681
  _a.sent();
682
+ return [3 /*break*/, 3];
683
+ case 2:
684
+ tx.partialSign(invoker);
679
685
  _a.label = 3;
680
686
  case 3:
681
687
  rawTx = tx.serialize();
682
- return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, rawTx)];
688
+ if (!hash.lastValidBlockHeight || !tx.signature || !hash.blockhash)
689
+ throw Error("Error with transaction parameters.");
690
+ confirmationStrategy = {
691
+ lastValidBlockHeight: hash.lastValidBlockHeight,
692
+ signature: (0, bs58_1.encode)(tx.signature),
693
+ blockhash: hash.blockhash,
694
+ };
695
+ return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, rawTx, confirmationStrategy)];
683
696
  case 4:
684
697
  signature = _a.sent();
685
698
  return [2 /*return*/, signature];
@@ -760,12 +773,13 @@ var StreamClient = /** @class */ (function () {
760
773
  withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
761
774
  systemProgram: web3_js_1.SystemProgram.programId,
762
775
  }));
763
- return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
776
+ return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
764
777
  case 6:
765
778
  hash = _f.sent();
766
779
  tx = (_e = new web3_js_1.Transaction({
767
780
  feePayer: sender.publicKey,
768
- recentBlockhash: hash.blockhash,
781
+ blockhash: hash.blockhash,
782
+ lastValidBlockHeight: hash.lastValidBlockHeight,
769
783
  })).add.apply(_e, __spreadArray([], __read(ixs), false));
770
784
  tx.partialSign(metadata);
771
785
  return [2 /*return*/, { tx: tx, metadata: metadata }];
@@ -858,18 +872,26 @@ function signAllTransactionWithRecipients(sender, batch) {
858
872
  }
859
873
  function sendAndConfirmStreamRawTransaction(connection, batchItem) {
860
874
  return __awaiter(this, void 0, void 0, function () {
861
- var rawTx, signature, error_1;
862
- return __generator(this, function (_a) {
863
- switch (_a.label) {
875
+ var rawTx, _a, lastValidBlockHeight, signature, recentBlockhash, confirmationStrategy, completedTxSignature, error_1;
876
+ return __generator(this, function (_b) {
877
+ switch (_b.label) {
864
878
  case 0:
865
- _a.trys.push([0, 2, , 3]);
879
+ _b.trys.push([0, 2, , 3]);
866
880
  rawTx = batchItem.tx.serialize();
867
- return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(connection, rawTx)];
881
+ _a = batchItem.tx, lastValidBlockHeight = _a.lastValidBlockHeight, signature = _a.signature, recentBlockhash = _a.recentBlockhash;
882
+ if (!lastValidBlockHeight || !signature || !recentBlockhash)
883
+ throw { recipient: batchItem.recipient, error: "no recent blockhash" };
884
+ confirmationStrategy = {
885
+ lastValidBlockHeight: lastValidBlockHeight,
886
+ signature: (0, bs58_1.encode)(signature),
887
+ blockhash: recentBlockhash,
888
+ };
889
+ return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(connection, rawTx, confirmationStrategy)];
868
890
  case 1:
869
- signature = _a.sent();
870
- return [2 /*return*/, __assign(__assign({}, batchItem), { signature: signature })];
891
+ completedTxSignature = _b.sent();
892
+ return [2 /*return*/, __assign(__assign({}, batchItem), { signature: completedTxSignature })];
871
893
  case 2:
872
- error_1 = _a.sent();
894
+ error_1 = _b.sent();
873
895
  throw { recipient: batchItem.recipient, error: error_1 };
874
896
  case 3: return [2 /*return*/];
875
897
  }
@@ -120,7 +120,7 @@ beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
120
120
  connection = new web3.Connection(web3.clusterApiUrl(), "confirmed");
121
121
  sender = new anchor_1.Wallet(web3.Keypair.generate());
122
122
  recipient = new anchor_1.Wallet(web3.Keypair.generate());
123
- recipients = __spreadArray([], __read(new Array(30)), false).map(function () { return new anchor_1.Wallet(web3.Keypair.generate()); });
123
+ recipients = __spreadArray([], __read(new Array(10)), false).map(function () { return new anchor_1.Wallet(web3.Keypair.generate()); });
124
124
  return [4 /*yield*/, (0, airdrop_request_1.requestAirdrop)(sender, connection)];
125
125
  case 1:
126
126
  _a.sent();
@@ -211,7 +211,7 @@ exports.timePeriodOptions = [
211
211
  { value: exports.PERIOD.YEAR, label: "year" },
212
212
  ];
213
213
  test("Can create multiple stremas", function () { return __awaiter(void 0, void 0, void 0, function () {
214
- var now, recipientsPayload, values, data, response;
214
+ var now, recipientsPayload, values, data, response, errors;
215
215
  return __generator(this, function (_a) {
216
216
  switch (_a.label) {
217
217
  case 0:
@@ -242,6 +242,8 @@ test("Can create multiple stremas", function () { return __awaiter(void 0, void
242
242
  return [4 /*yield*/, (streamInstance === null || streamInstance === void 0 ? void 0 : streamInstance.createMultiple(data))];
243
243
  case 1:
244
244
  response = _a.sent();
245
+ errors = response === null || response === void 0 ? void 0 : response.errors;
246
+ console.log(errors);
245
247
  return [2 /*return*/, response];
246
248
  }
247
249
  });
@@ -85,6 +85,7 @@ var createStreamInstruction = function (data, programId, accounts) {
85
85
  bufferData = buffer_1.Buffer.concat([
86
86
  buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:create")).slice(0, 8),
87
87
  bufferData,
88
+ buffer_1.Buffer.alloc(10)
88
89
  ]);
89
90
  return new web3_js_1.TransactionInstruction({
90
91
  keys: keys,
@@ -119,6 +120,7 @@ var withdrawStreamInstruction = function (amount, programId, _a) {
119
120
  data = buffer_1.Buffer.concat([
120
121
  buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:withdraw")).slice(0, 8),
121
122
  data,
123
+ buffer_1.Buffer.alloc(10)
122
124
  ]);
123
125
  return new web3_js_1.TransactionInstruction({
124
126
  keys: keys,
@@ -148,7 +150,10 @@ var cancelStreamInstruction = function (programId, _a) {
148
150
  { pubkey: mint, isSigner: false, isWritable: false },
149
151
  { pubkey: tokenProgram, isSigner: false, isWritable: false },
150
152
  ];
151
- var data = buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:cancel")).slice(0, 8);
153
+ var data = buffer_1.Buffer.concat([
154
+ buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:cancel")).slice(0, 8),
155
+ buffer_1.Buffer.alloc(10),
156
+ ]);
152
157
  return new web3_js_1.TransactionInstruction({
153
158
  keys: keys,
154
159
  programId: programId,
@@ -169,7 +174,10 @@ var transferStreamInstruction = function (programId, _a) {
169
174
  { pubkey: associatedTokenProgram, isSigner: false, isWritable: false },
170
175
  { pubkey: systemProgram, isSigner: false, isWritable: false },
171
176
  ];
172
- var data = buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:transfer_recipient")).slice(0, 8);
177
+ var data = buffer_1.Buffer.concat([
178
+ buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:transfer_recipient")).slice(0, 8),
179
+ buffer_1.Buffer.alloc(10),
180
+ ]);
173
181
  return new web3_js_1.TransactionInstruction({
174
182
  keys: keys,
175
183
  programId: programId,
@@ -204,6 +212,7 @@ var topupStreamInstruction = function (amount, programId, _a) {
204
212
  data = buffer_1.Buffer.concat([
205
213
  buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:topup")).slice(0, 8),
206
214
  data,
215
+ buffer_1.Buffer.alloc(10)
207
216
  ]);
208
217
  return new web3_js_1.TransactionInstruction({
209
218
  keys: keys,
package/dist/types.d.ts CHANGED
@@ -85,7 +85,7 @@ export interface WithdrawStreamParams extends WithdrawStreamData {
85
85
  cluster?: ClusterExtended;
86
86
  }
87
87
  export interface WithdrawParams extends WithdrawStreamData {
88
- invoker: Wallet;
88
+ invoker: Wallet | Keypair;
89
89
  }
90
90
  export interface TopupStreamData {
91
91
  id: string;
@@ -97,7 +97,7 @@ export interface TopupStreamParams extends TopupStreamData {
97
97
  cluster?: ClusterExtended;
98
98
  }
99
99
  export interface TopupParams extends TopupStreamData {
100
- invoker: Wallet;
100
+ invoker: Wallet | Keypair;
101
101
  }
102
102
  export interface CancelStreamData {
103
103
  id: string;
@@ -108,7 +108,7 @@ export interface CancelStreamParams extends CancelStreamData {
108
108
  cluster?: ClusterExtended;
109
109
  }
110
110
  export interface CancelParams extends CancelStreamData {
111
- invoker: Wallet;
111
+ invoker: Wallet | Keypair;
112
112
  }
113
113
  export interface TransferStreamData {
114
114
  id: string;
@@ -120,7 +120,7 @@ export interface TransferStreamParams extends TransferStreamData {
120
120
  cluster?: ClusterExtended;
121
121
  }
122
122
  export interface TransferParams extends TransferStreamData {
123
- invoker: Wallet;
123
+ invoker: Wallet | Keypair;
124
124
  }
125
125
  export interface GetStreamParams {
126
126
  connection: Connection;
@@ -176,6 +176,49 @@ export interface Stream {
176
176
  canTopup: boolean;
177
177
  name: string;
178
178
  withdrawalFrequency: number;
179
+ unlocked(currentTimestamp: number, decimals: number): number;
180
+ }
181
+ export declare class Contract implements Stream {
182
+ magic: number;
183
+ version: number;
184
+ createdAt: number;
185
+ withdrawnAmount: BN;
186
+ canceledAt: number;
187
+ end: number;
188
+ lastWithdrawnAt: number;
189
+ sender: string;
190
+ senderTokens: string;
191
+ recipient: string;
192
+ recipientTokens: string;
193
+ mint: string;
194
+ escrowTokens: string;
195
+ streamflowTreasury: string;
196
+ streamflowTreasuryTokens: string;
197
+ streamflowFeeTotal: BN;
198
+ streamflowFeeWithdrawn: BN;
199
+ streamflowFeePercent: number;
200
+ partnerFeeTotal: BN;
201
+ partnerFeeWithdrawn: BN;
202
+ partnerFeePercent: number;
203
+ partner: string;
204
+ partnerTokens: string;
205
+ start: number;
206
+ depositedAmount: BN;
207
+ period: number;
208
+ amountPerPeriod: BN;
209
+ cliff: number;
210
+ cliffAmount: BN;
211
+ cancelableBySender: boolean;
212
+ cancelableByRecipient: boolean;
213
+ automaticWithdrawal: boolean;
214
+ transferableBySender: boolean;
215
+ transferableByRecipient: boolean;
216
+ canTopup: boolean;
217
+ name: string;
218
+ withdrawalFrequency: number;
219
+ constructor(stream: DecodedStream);
220
+ unlocked(currentTimestamp: number, decimals: number): number;
221
+ remaining(decimals: number): number;
179
222
  }
180
223
  export interface DecodedStream {
181
224
  magic: BN;
package/dist/types.js CHANGED
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TransferCancelOptions = exports.LocalCluster = exports.StreamType = exports.StreamDirection = exports.Cluster = void 0;
6
+ exports.TransferCancelOptions = exports.Contract = exports.LocalCluster = exports.StreamType = exports.StreamDirection = exports.Cluster = void 0;
7
+ var bn_js_1 = __importDefault(require("bn.js"));
8
+ var utils_1 = require("./utils");
4
9
  var wallet_adapter_base_1 = require("@solana/wallet-adapter-base");
5
10
  Object.defineProperty(exports, "Cluster", { enumerable: true, get: function () { return wallet_adapter_base_1.WalletAdapterNetwork; } });
6
11
  var StreamDirection;
@@ -19,6 +24,64 @@ var LocalCluster;
19
24
  (function (LocalCluster) {
20
25
  LocalCluster["Local"] = "local";
21
26
  })(LocalCluster = exports.LocalCluster || (exports.LocalCluster = {}));
27
+ var Contract = /** @class */ (function () {
28
+ function Contract(stream) {
29
+ var _a;
30
+ this.magic = stream.magic.toNumber();
31
+ this.version = stream.version.toNumber();
32
+ this.createdAt = stream.createdAt.toNumber();
33
+ this.withdrawnAmount = stream.withdrawnAmount;
34
+ this.canceledAt = stream.canceledAt.toNumber();
35
+ this.end = stream.end.toNumber();
36
+ this.lastWithdrawnAt = stream.lastWithdrawnAt.toNumber();
37
+ this.sender = stream.sender.toBase58();
38
+ this.senderTokens = stream.senderTokens.toBase58();
39
+ this.recipient = stream.recipient.toBase58();
40
+ this.recipientTokens = stream.recipientTokens.toBase58();
41
+ this.mint = stream.mint.toBase58();
42
+ this.escrowTokens = stream.escrowTokens.toBase58();
43
+ this.streamflowTreasury = stream.streamflowTreasury.toBase58();
44
+ this.streamflowTreasuryTokens =
45
+ stream.streamflowTreasuryTokens.toBase58();
46
+ this.streamflowFeeTotal = stream.streamflowFeeTotal;
47
+ this.streamflowFeeWithdrawn = stream.streamflowFeeWithdrawn;
48
+ this.streamflowFeePercent = stream.streamflowFeePercent.toNumber();
49
+ this.partnerFeeTotal = stream.partnerFeeTotal;
50
+ this.partnerFeeWithdrawn = stream.partnerFeeWithdrawn;
51
+ this.partnerFeePercent = stream.partnerFeePercent.toNumber();
52
+ this.partner = stream.partner.toBase58();
53
+ this.partnerTokens = (_a = stream.partnerTokens) === null || _a === void 0 ? void 0 : _a.toBase58();
54
+ this.start = stream.start.toNumber();
55
+ this.depositedAmount = stream.depositedAmount;
56
+ this.period = stream.period.toNumber();
57
+ this.amountPerPeriod = stream.amountPerPeriod;
58
+ this.cliff = stream.cliff.toNumber();
59
+ this.cliffAmount = stream.cliffAmount;
60
+ this.cancelableBySender = stream.cancelableBySender;
61
+ this.cancelableByRecipient = stream.cancelableByRecipient;
62
+ this.automaticWithdrawal = stream.automaticWithdrawal;
63
+ this.transferableBySender = stream.transferableBySender;
64
+ this.transferableByRecipient = stream.transferableByRecipient;
65
+ this.canTopup = stream.canTopup;
66
+ this.name = stream.name;
67
+ this.withdrawalFrequency = stream.withdrawFrequency.toNumber();
68
+ }
69
+ Contract.prototype.unlocked = function (currentTimestamp, decimals) {
70
+ var deposited = (0, utils_1.getNumberFromBN)(this.depositedAmount, decimals);
71
+ if (currentTimestamp < this.cliff)
72
+ return 0;
73
+ if (currentTimestamp > this.end)
74
+ return deposited;
75
+ var streamedBN = this.cliffAmount.add(new bn_js_1.default(Math.floor((currentTimestamp - this.cliff) / this.period)).mul(this.amountPerPeriod));
76
+ var streamed = (0, utils_1.getNumberFromBN)(streamedBN, decimals);
77
+ return streamed < deposited ? streamed : deposited;
78
+ };
79
+ Contract.prototype.remaining = function (decimals) {
80
+ return (0, utils_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
81
+ };
82
+ return Contract;
83
+ }());
84
+ exports.Contract = Contract;
22
85
  var TransferCancelOptions;
23
86
  (function (TransferCancelOptions) {
24
87
  TransferCancelOptions["Recipient"] = "recipient";
package/dist/utils.js CHANGED
@@ -52,9 +52,11 @@ var decodeStream = function (buf) {
52
52
  };
53
53
  };
54
54
  exports.decodeStream = decodeStream;
55
+ // DeprecationWarning: This object will be deprecated starting from the version 4.0.0. Use
56
+ // types/Contract instead
55
57
  var formatDecodedStream = function (stream) {
56
58
  var _a;
57
- return ({
59
+ var resp = {
58
60
  magic: stream.magic.toNumber(),
59
61
  version: stream.version.toNumber(),
60
62
  createdAt: stream.createdAt.toNumber(),
@@ -92,7 +94,10 @@ var formatDecodedStream = function (stream) {
92
94
  canTopup: stream.canTopup,
93
95
  name: stream.name,
94
96
  withdrawalFrequency: stream.withdrawFrequency.toNumber(),
95
- });
97
+ unlocked: function () { return 0; },
98
+ withdrawn: function () { return new bn_js_1.default(0); } //phantom method to preserve partial support of this object
99
+ };
100
+ return resp;
96
101
  };
97
102
  exports.formatDecodedStream = formatDecodedStream;
98
103
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "3.0.6",
3
+ "version": "3.0.9",
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/",
@@ -20,7 +20,7 @@
20
20
  "@project-serum/common": "^0.0.1-beta.3",
21
21
  "@solana/spl-token": "^0.1.8",
22
22
  "@solana/wallet-adapter-base": "^0.9.2",
23
- "@solana/web3.js": "^1.29.2",
23
+ "@solana/web3.js": "^1.42.0",
24
24
  "bn.js": "^5.2.0",
25
25
  "buffer-layout": "^1.2.1"
26
26
  }