@streamflow/stream 4.0.0 → 4.0.2

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.
@@ -757,25 +757,26 @@ var SolanaStreamClient = /** @class */ (function (_super) {
757
757
  };
758
758
  SolanaStreamClient.prototype.sign = function (invoker, tx, hash) {
759
759
  return __awaiter(this, void 0, void 0, function () {
760
- var rawTx, confirmationStrategy, signature;
760
+ var signedTx, rawTx, confirmationStrategy, signature;
761
761
  return __generator(this, function (_a) {
762
762
  switch (_a.label) {
763
763
  case 0:
764
764
  if (!(0, utils_1.isSignerWallet)(invoker)) return [3 /*break*/, 2];
765
765
  return [4 /*yield*/, invoker.signTransaction(tx)];
766
766
  case 1:
767
- _a.sent();
767
+ signedTx = _a.sent();
768
768
  return [3 /*break*/, 3];
769
769
  case 2:
770
770
  tx.partialSign(invoker);
771
+ signedTx = tx;
771
772
  _a.label = 3;
772
773
  case 3:
773
- rawTx = tx.serialize();
774
- if (!hash.lastValidBlockHeight || !tx.signature || !hash.blockhash)
774
+ rawTx = signedTx.serialize();
775
+ if (!hash.lastValidBlockHeight || !signedTx.signature || !hash.blockhash)
775
776
  throw Error("Error with transaction parameters.");
776
777
  confirmationStrategy = {
777
778
  lastValidBlockHeight: hash.lastValidBlockHeight,
778
- signature: bs58_1.default.encode(tx.signature),
779
+ signature: bs58_1.default.encode(signedTx.signature),
779
780
  blockhash: hash.blockhash,
780
781
  };
781
782
  return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, rawTx, confirmationStrategy)];
@@ -792,41 +793,42 @@ var SolanaStreamClient = /** @class */ (function (_super) {
792
793
  SolanaStreamClient.prototype.update = function (data, _a) {
793
794
  var invoker = _a.invoker;
794
795
  return __awaiter(this, void 0, void 0, function () {
795
- var ixs, streamPublicKey, escrow, commitment, hash, tx, signature;
796
- var _b;
797
- return __generator(this, function (_c) {
798
- switch (_c.label) {
796
+ var streamPublicKey, escrow, updateIx, commitment, hash, tx, signature;
797
+ return __generator(this, function (_b) {
798
+ switch (_b.label) {
799
799
  case 0:
800
800
  if (!invoker.publicKey) {
801
801
  throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
802
802
  }
803
- ixs = [];
804
803
  streamPublicKey = new web3_js_1.PublicKey(data.id);
805
804
  return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
806
805
  case 1:
807
- escrow = _c.sent();
808
- if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
806
+ escrow = _b.sent();
807
+ if (!escrow) {
809
808
  throw new Error("Couldn't get account info");
810
809
  }
811
- ixs.push((0, instructions_1.updateStreamInstruction)(data, this.programId, {
810
+ updateIx = (0, instructions_1.updateStreamInstruction)(data, this.programId, {
812
811
  authority: invoker.publicKey,
813
812
  metadata: streamPublicKey,
814
813
  withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
815
814
  systemProgram: web3_js_1.SystemProgram.programId,
816
- }));
815
+ });
817
816
  commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
818
817
  return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
819
818
  case 2:
820
- hash = _c.sent();
821
- tx = (_b = new web3_js_1.Transaction({
819
+ hash = _b.sent();
820
+ tx = new web3_js_1.Transaction({
822
821
  feePayer: invoker.publicKey,
823
822
  blockhash: hash.blockhash,
824
823
  lastValidBlockHeight: hash.lastValidBlockHeight,
825
- })).add.apply(_b, __spreadArray([], __read(ixs), false));
824
+ }).add(updateIx);
826
825
  return [4 /*yield*/, this.sign(invoker, tx, hash)];
827
826
  case 3:
828
- signature = _c.sent();
829
- return [2 /*return*/, { ixs: ixs, tx: signature }];
827
+ signature = _b.sent();
828
+ return [2 /*return*/, {
829
+ ixs: [updateIx],
830
+ tx: signature,
831
+ }];
830
832
  }
831
833
  });
832
834
  });
@@ -254,7 +254,6 @@ var withdrawStreamInstruction = function (amount, programId, _a) {
254
254
  };
255
255
  exports.withdrawStreamInstruction = withdrawStreamInstruction;
256
256
  var updateStreamInstruction = function (params, programId, _a) {
257
- var _b, _c;
258
257
  var authority = _a.authority, metadata = _a.metadata, withdrawor = _a.withdrawor, systemProgram = _a.systemProgram;
259
258
  var keys = [
260
259
  { pubkey: authority, isSigner: true, isWritable: true },
@@ -265,8 +264,12 @@ var updateStreamInstruction = function (params, programId, _a) {
265
264
  var data = buffer_1.Buffer.alloc(100);
266
265
  var decodedData = {
267
266
  enable_automatic_withdrawal: Number(params.enableAutomaticWithdrawal),
268
- withdraw_frequency: (_b = params.withdrawFrequency) === null || _b === void 0 ? void 0 : _b.toArrayLike(buffer_1.Buffer, "le", 8),
269
- amount_per_period: (_c = params.amountPerPeriod) === null || _c === void 0 ? void 0 : _c.toArrayLike(buffer_1.Buffer, "le", 8),
267
+ withdraw_frequency: params.withdrawFrequency
268
+ ? params.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8)
269
+ : undefined,
270
+ amount_per_period: params.amountPerPeriod
271
+ ? params.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8)
272
+ : undefined,
270
273
  };
271
274
  var encodeLength = Layout.encodeUpdateStream(decodedData, data);
272
275
  data = data.slice(0, encodeLength);
@@ -144,9 +144,9 @@ var encodeUpdateStream = function (values, data) {
144
144
  enable_automatic_withdrawal_exists: values.enable_automatic_withdrawal ? 1 : 0,
145
145
  enable_automatic_withdrawal: (_a = values.enable_automatic_withdrawal) !== null && _a !== void 0 ? _a : 0,
146
146
  withdraw_frequency_exists: values.withdraw_frequency ? 1 : 0,
147
- withdraw_frequency: (_b = values.withdraw_frequency) !== null && _b !== void 0 ? _b : new Uint8Array(),
147
+ withdraw_frequency: (_b = values.withdraw_frequency) !== null && _b !== void 0 ? _b : 0,
148
148
  amount_per_period_exists: values.amount_per_period ? 1 : 0,
149
- amount_per_period: (_c = values.amount_per_period) !== null && _c !== void 0 ? _c : new Uint8Array(),
149
+ amount_per_period: (_c = values.amount_per_period) !== null && _c !== void 0 ? _c : 0,
150
150
  }, data);
151
151
  };
152
152
  exports.encodeUpdateStream = encodeUpdateStream;
@@ -195,28 +195,26 @@ exports.isSignerWallet = isSignerWallet;
195
195
  */
196
196
  function signAllTransactionWithRecipients(sender, items) {
197
197
  return __awaiter(this, void 0, void 0, function () {
198
- var signed_batch, isKeypair, isWallet;
198
+ var isKeypair, isWallet, signedTxs_1;
199
199
  return __generator(this, function (_a) {
200
200
  switch (_a.label) {
201
201
  case 0:
202
- signed_batch = [];
203
202
  isKeypair = sender instanceof web3_js_1.Keypair;
204
203
  isWallet = isSignerWallet(sender);
205
- if (!isKeypair && !isWallet)
206
- return [2 /*return*/, signed_batch];
207
204
  if (!isKeypair) return [3 /*break*/, 1];
208
- items.map(function (t) {
209
- t.tx.partialSign(sender);
210
- return { tx: t.tx, recipient: t.recipient };
211
- });
212
- return [3 /*break*/, 3];
205
+ return [2 /*return*/, items.map(function (t) {
206
+ t.tx.partialSign(sender);
207
+ return { tx: t.tx, recipient: t.recipient };
208
+ })];
213
209
  case 1:
214
210
  if (!isWallet) return [3 /*break*/, 3];
215
211
  return [4 /*yield*/, sender.signAllTransactions(items.map(function (t) { return t.tx; }))];
216
212
  case 2:
217
- _a.sent();
218
- _a.label = 3;
219
- case 3: return [2 /*return*/, items];
213
+ signedTxs_1 = _a.sent();
214
+ return [2 /*return*/, items.map(function (item, index) { return (__assign(__assign({}, item), { tx: signedTxs_1[index] })); })];
215
+ case 3:
216
+ // If signer is not passed
217
+ return [2 /*return*/, []];
220
218
  }
221
219
  });
222
220
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
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/",