@streamflow/stream 5.8.1 → 5.9.0

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.
@@ -71,6 +71,10 @@ export default class SolanaStreamClient extends BaseStreamClient {
71
71
  * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
72
72
  */
73
73
  private prepareStreamTransaction;
74
+ /**
75
+ * Utility function that checks whether associated token account for the recipient exists and adds an instruction to add if not
76
+ */
77
+ private checkAssociatedTokenAccount;
74
78
  /**
75
79
  * Utility function to generate metadata for a Contract or return existing Pubkey
76
80
  */
@@ -130,6 +130,7 @@ var buffer_1 = require("buffer");
130
130
  var bs58_1 = __importDefault(require("bs58"));
131
131
  var spl_token_1 = require("@solana/spl-token");
132
132
  var web3_js_1 = require("@solana/web3.js");
133
+ var spl_token_2 = require("@solana/spl-token");
133
134
  var borsh = __importStar(require("borsh"));
134
135
  var types_1 = require("./types");
135
136
  var utils_1 = require("./utils");
@@ -520,6 +521,9 @@ var SolanaStreamClient = /** @class */ (function (_super) {
520
521
  return [4 /*yield*/, (0, utils_1.ata)(data.mint, data.partner)];
521
522
  case 3:
522
523
  partnerTokens = _d.sent();
524
+ return [4 /*yield*/, this.checkAssociatedTokenAccount(data, { invoker: invoker }, ixs)];
525
+ case 4:
526
+ _d.sent();
523
527
  ixs.push((0, instructions_1.withdrawStreamInstruction)(amount, this.programId, {
524
528
  authority: invoker.publicKey,
525
529
  recipient: invoker.publicKey,
@@ -535,7 +539,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
535
539
  }));
536
540
  commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
537
541
  return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
538
- case 4:
542
+ case 5:
539
543
  hash = _d.sent();
540
544
  tx = (_c = new web3_js_1.Transaction({
541
545
  feePayer: invoker.publicKey,
@@ -543,7 +547,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
543
547
  lastValidBlockHeight: hash.lastValidBlockHeight,
544
548
  })).add.apply(_c, __spreadArray([], __read(ixs), false));
545
549
  return [4 /*yield*/, this.sign(invoker, tx, hash)];
546
- case 5:
550
+ case 6:
547
551
  signature = _d.sent();
548
552
  return [2 /*return*/, { ixs: ixs, txId: signature }];
549
553
  }
@@ -580,6 +584,9 @@ var SolanaStreamClient = /** @class */ (function (_super) {
580
584
  case 3:
581
585
  partnerTokens = _d.sent();
582
586
  ixs = [];
587
+ return [4 /*yield*/, this.checkAssociatedTokenAccount(data, { invoker: invoker }, ixs)];
588
+ case 4:
589
+ _d.sent();
583
590
  ixs.push((0, instructions_1.cancelStreamInstruction)(this.programId, {
584
591
  authority: invoker.publicKey,
585
592
  sender: data.sender,
@@ -597,7 +604,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
597
604
  }));
598
605
  commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
599
606
  return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
600
- case 4:
607
+ case 5:
601
608
  hash = _d.sent();
602
609
  tx = (_c = new web3_js_1.Transaction({
603
610
  feePayer: invoker.publicKey,
@@ -605,7 +612,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
605
612
  lastValidBlockHeight: hash.lastValidBlockHeight,
606
613
  })).add.apply(_c, __spreadArray([], __read(ixs), false));
607
614
  return [4 /*yield*/, this.sign(invoker, tx, hash)];
608
- case 5:
615
+ case 6:
609
616
  signature = _d.sent();
610
617
  return [2 /*return*/, { ixs: ixs, txId: signature }];
611
618
  }
@@ -1009,6 +1016,26 @@ var SolanaStreamClient = /** @class */ (function (_super) {
1009
1016
  });
1010
1017
  });
1011
1018
  };
1019
+ /**
1020
+ * Utility function that checks whether associated token account for the recipient exists and adds an instruction to add if not
1021
+ */
1022
+ SolanaStreamClient.prototype.checkAssociatedTokenAccount = function (data, _a, ixs) {
1023
+ var invoker = _a.invoker;
1024
+ return __awaiter(this, void 0, void 0, function () {
1025
+ var accountExists;
1026
+ return __generator(this, function (_b) {
1027
+ switch (_b.label) {
1028
+ case 0: return [4 /*yield*/, this.connection.getAccountInfo(data.recipientTokens)];
1029
+ case 1:
1030
+ accountExists = _b.sent();
1031
+ if (!(accountExists === null || accountExists === void 0 ? void 0 : accountExists.data)) {
1032
+ ixs.push((0, spl_token_2.createAssociatedTokenAccountInstruction)(invoker.publicKey, data.recipientTokens, data.recipient, data.mint, spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID));
1033
+ }
1034
+ return [2 /*return*/];
1035
+ }
1036
+ });
1037
+ });
1038
+ };
1012
1039
  /**
1013
1040
  * Utility function to generate metadata for a Contract or return existing Pubkey
1014
1041
  */
@@ -280,6 +280,11 @@ export interface CreateMultipleStreamsValues {
280
280
  referral: string;
281
281
  recipients: Recipient[];
282
282
  }
283
+ export interface CheckAssociatedTokenAccountData {
284
+ recipient: PublicKey;
285
+ recipientTokens: PublicKey;
286
+ mint: PublicKey;
287
+ }
283
288
  export interface BatchItem {
284
289
  recipient: string;
285
290
  tx: Transaction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "5.8.1",
3
+ "version": "5.9.0",
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/",
@@ -11,7 +11,7 @@
11
11
  "lint": "eslint .",
12
12
  "prepublishOnly": "npm run lint && npm test && npm run build"
13
13
  },
14
- "gitHead": "350ddca7a88b33289ea764f8b84bceba7b64c173",
14
+ "gitHead": "977658bcb7bb376fe528c69e2240a77cdb0bd1c3",
15
15
  "devDependencies": {
16
16
  "@types/bn.js": "5.1.1",
17
17
  "@types/ethereum-checksum-address": "^0.0.0",