@streamflow/stream 3.0.3 → 3.0.4

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.
@@ -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
@@ -240,8 +241,8 @@ var StreamClient = /** @class */ (function () {
240
241
  */
241
242
  StreamClient.prototype.createMultiple = function (data) {
242
243
  return __awaiter(this, void 0, void 0, function () {
243
- 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;
244
- var e_2, _b, e_1, _c;
244
+ 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;
245
+ var e_1, _b, e_2, _c;
245
246
  var _this = this;
246
247
  return __generator(this, function (_d) {
247
248
  switch (_d.label) {
@@ -251,52 +252,53 @@ var StreamClient = /** @class */ (function () {
251
252
  metadataToRecipient = {};
252
253
  errors = [];
253
254
  signatures = [];
254
- chunkSize = 10;
255
+ chunkSize = 100;
255
256
  chunkes = [];
256
- for (i = 0; i < recipientsData.length; i += chunkSize) {
257
- chunk = recipientsData.slice(i, i + chunkSize);
258
- chunkes.push(chunk);
259
- }
257
+ batch = [];
260
258
  _d.label = 1;
261
259
  case 1:
262
- _d.trys.push([1, 16, 17, 18]);
263
- chunkes_1 = __values(chunkes), chunkes_1_1 = chunkes_1.next();
260
+ _d.trys.push([1, 6, 7, 8]);
261
+ recipientsData_1 = __values(recipientsData), recipientsData_1_1 = recipientsData_1.next();
264
262
  _d.label = 2;
265
263
  case 2:
266
- if (!!chunkes_1_1.done) return [3 /*break*/, 15];
267
- chunk = chunkes_1_1.value;
268
- batch = [];
269
- _d.label = 3;
270
- case 3:
271
- _d.trys.push([3, 8, 9, 10]);
272
- chunk_1 = (e_1 = void 0, __values(chunk)), chunk_1_1 = chunk_1.next();
273
- _d.label = 4;
274
- case 4:
275
- if (!!chunk_1_1.done) return [3 /*break*/, 7];
276
- recipientData = chunk_1_1.value;
264
+ if (!!recipientsData_1_1.done) return [3 /*break*/, 5];
265
+ recipientData = recipientsData_1_1.value;
277
266
  return [4 /*yield*/, this.prepareStreamTransaction(recipientData, data)];
278
- case 5:
267
+ case 3:
279
268
  _a = _d.sent(), tx = _a.tx, metadata = _a.metadata;
280
269
  metadataPubKey = metadata.publicKey.toBase58();
281
270
  metadataToRecipient[metadataPubKey] = recipientData;
282
271
  metadatas.push(metadata);
283
272
  batch.push({ tx: tx, recipient: recipientData.recipient });
284
- _d.label = 6;
273
+ _d.label = 4;
274
+ case 4:
275
+ recipientsData_1_1 = recipientsData_1.next();
276
+ return [3 /*break*/, 2];
277
+ case 5: return [3 /*break*/, 8];
285
278
  case 6:
286
- chunk_1_1 = chunk_1.next();
287
- return [3 /*break*/, 4];
288
- case 7: return [3 /*break*/, 10];
289
- case 8:
290
279
  e_1_1 = _d.sent();
291
280
  e_1 = { error: e_1_1 };
292
- return [3 /*break*/, 10];
293
- case 9:
281
+ return [3 /*break*/, 8];
282
+ case 7:
294
283
  try {
295
- if (chunk_1_1 && !chunk_1_1.done && (_c = chunk_1.return)) _c.call(chunk_1);
284
+ if (recipientsData_1_1 && !recipientsData_1_1.done && (_b = recipientsData_1.return)) _b.call(recipientsData_1);
296
285
  }
297
286
  finally { if (e_1) throw e_1.error; }
298
287
  return [7 /*endfinally*/];
299
- case 10: return [4 /*yield*/, signAllTransactionWithRecipients(sender, batch)];
288
+ case 8:
289
+ for (i = 0; i < batch.length; i += chunkSize) {
290
+ chunk = batch.slice(i, i + chunkSize);
291
+ chunkes.push(chunk);
292
+ }
293
+ _d.label = 9;
294
+ case 9:
295
+ _d.trys.push([9, 16, 17, 18]);
296
+ chunkes_1 = __values(chunkes), chunkes_1_1 = chunkes_1.next();
297
+ _d.label = 10;
298
+ case 10:
299
+ if (!!chunkes_1_1.done) return [3 /*break*/, 15];
300
+ chunk = chunkes_1_1.value;
301
+ return [4 /*yield*/, signAllTransactionWithRecipients(sender, chunk)];
300
302
  case 11:
301
303
  signed_batch = _d.sent();
302
304
  batchTransactionsCalls = signed_batch.map(function (el) {
@@ -321,7 +323,7 @@ var StreamClient = /** @class */ (function () {
321
323
  _d.label = 14;
322
324
  case 14:
323
325
  chunkes_1_1 = chunkes_1.next();
324
- return [3 /*break*/, 2];
326
+ return [3 /*break*/, 10];
325
327
  case 15: return [3 /*break*/, 18];
326
328
  case 16:
327
329
  e_2_1 = _d.sent();
@@ -329,7 +331,7 @@ var StreamClient = /** @class */ (function () {
329
331
  return [3 /*break*/, 18];
330
332
  case 17:
331
333
  try {
332
- if (chunkes_1_1 && !chunkes_1_1.done && (_b = chunkes_1.return)) _b.call(chunkes_1);
334
+ if (chunkes_1_1 && !chunkes_1_1.done && (_c = chunkes_1.return)) _c.call(chunkes_1);
333
335
  }
334
336
  finally { if (e_2) throw e_2.error; }
335
337
  return [7 /*endfinally*/];
@@ -753,12 +755,13 @@ var StreamClient = /** @class */ (function () {
753
755
  withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
754
756
  systemProgram: web3_js_1.SystemProgram.programId,
755
757
  }));
756
- return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
758
+ return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
757
759
  case 6:
758
760
  hash = _f.sent();
759
761
  tx = (_e = new web3_js_1.Transaction({
760
762
  feePayer: sender.publicKey,
761
- recentBlockhash: hash.blockhash,
763
+ blockhash: hash.blockhash,
764
+ lastValidBlockHeight: hash.lastValidBlockHeight,
762
765
  })).add.apply(_e, __spreadArray([], __read(ixs), false));
763
766
  tx.partialSign(metadata);
764
767
  return [2 /*return*/, { tx: tx, metadata: metadata }];
@@ -852,18 +855,26 @@ function signAllTransactionWithRecipients(sender, batch) {
852
855
  }
853
856
  function sendAndConfirmStreamRawTransaction(connection, batchItem) {
854
857
  return __awaiter(this, void 0, void 0, function () {
855
- var rawTx, signature, error_1;
856
- return __generator(this, function (_a) {
857
- switch (_a.label) {
858
+ var rawTx, _a, lastValidBlockHeight, signature, recentBlockhash, confirmationStrategy, completedTxSignature, error_1;
859
+ return __generator(this, function (_b) {
860
+ switch (_b.label) {
858
861
  case 0:
859
- _a.trys.push([0, 2, , 3]);
862
+ _b.trys.push([0, 2, , 3]);
860
863
  rawTx = batchItem.tx.serialize();
861
- return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(connection, rawTx)];
864
+ _a = batchItem.tx, lastValidBlockHeight = _a.lastValidBlockHeight, signature = _a.signature, recentBlockhash = _a.recentBlockhash;
865
+ if (!lastValidBlockHeight || !signature || !recentBlockhash)
866
+ throw { recipient: batchItem.recipient, error: "no recent blockhash" };
867
+ confirmationStrategy = {
868
+ lastValidBlockHeight: lastValidBlockHeight,
869
+ signature: (0, bs58_1.encode)(signature),
870
+ blockhash: recentBlockhash,
871
+ };
872
+ return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(connection, rawTx, confirmationStrategy)];
862
873
  case 1:
863
- signature = _a.sent();
864
- return [2 /*return*/, __assign(__assign({}, batchItem), { signature: signature })];
874
+ completedTxSignature = _b.sent();
875
+ return [2 /*return*/, __assign(__assign({}, batchItem), { signature: completedTxSignature })];
865
876
  case 2:
866
- error_1 = _a.sent();
877
+ error_1 = _b.sent();
867
878
  throw { recipient: batchItem.recipient, error: error_1 };
868
879
  case 3: return [2 /*return*/];
869
880
  }
@@ -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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
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
  }