@streamflow/stream 5.9.0 → 5.9.1

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.
@@ -72,9 +72,9 @@ export default class SolanaStreamClient extends BaseStreamClient {
72
72
  */
73
73
  private prepareStreamTransaction;
74
74
  /**
75
- * Utility function that checks whether associated token account for the recipient exists and adds an instruction to add if not
75
+ * Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
76
76
  */
77
- private checkAssociatedTokenAccount;
77
+ private checkAssociatedTokenAccounts;
78
78
  /**
79
79
  * Utility function to generate metadata for a Contract or return existing Pubkey
80
80
  */
@@ -521,7 +521,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
521
521
  return [4 /*yield*/, (0, utils_1.ata)(data.mint, data.partner)];
522
522
  case 3:
523
523
  partnerTokens = _d.sent();
524
- return [4 /*yield*/, this.checkAssociatedTokenAccount(data, { invoker: invoker }, ixs)];
524
+ return [4 /*yield*/, this.checkAssociatedTokenAccounts(data, { invoker: invoker }, ixs)];
525
525
  case 4:
526
526
  _d.sent();
527
527
  ixs.push((0, instructions_1.withdrawStreamInstruction)(amount, this.programId, {
@@ -584,7 +584,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
584
584
  case 3:
585
585
  partnerTokens = _d.sent();
586
586
  ixs = [];
587
- return [4 /*yield*/, this.checkAssociatedTokenAccount(data, { invoker: invoker }, ixs)];
587
+ return [4 /*yield*/, this.checkAssociatedTokenAccounts(data, { invoker: invoker }, ixs)];
588
588
  case 4:
589
589
  _d.sent();
590
590
  ixs.push((0, instructions_1.cancelStreamInstruction)(this.programId, {
@@ -1017,19 +1017,38 @@ var SolanaStreamClient = /** @class */ (function (_super) {
1017
1017
  });
1018
1018
  };
1019
1019
  /**
1020
- * Utility function that checks whether associated token account for the recipient exists and adds an instruction to add if not
1020
+ * Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
1021
1021
  */
1022
- SolanaStreamClient.prototype.checkAssociatedTokenAccount = function (data, _a, ixs) {
1023
- var invoker = _a.invoker;
1022
+ SolanaStreamClient.prototype.checkAssociatedTokenAccounts = function (data, _a, ixs) {
1023
+ var invoker = _a.invoker, checkTokenAccounts = _a.checkTokenAccounts;
1024
1024
  return __awaiter(this, void 0, void 0, function () {
1025
- var accountExists;
1025
+ var checkedKeys, accountArrays, response, i;
1026
1026
  return __generator(this, function (_b) {
1027
1027
  switch (_b.label) {
1028
- case 0: return [4 /*yield*/, this.connection.getAccountInfo(data.recipientTokens)];
1028
+ case 0:
1029
+ if (!checkTokenAccounts) {
1030
+ return [2 /*return*/];
1031
+ }
1032
+ checkedKeys = new Set();
1033
+ accountArrays = [
1034
+ [data.sender, data.senderTokens],
1035
+ [data.recipient, data.recipientTokens],
1036
+ [data.partner, data.partnerTokens],
1037
+ [data.streamflowTreasury, data.streamflowTreasuryTokens],
1038
+ ].filter(function (value) {
1039
+ if (checkedKeys.has(value[1])) {
1040
+ return false;
1041
+ }
1042
+ checkedKeys.add(value[1]);
1043
+ return true;
1044
+ });
1045
+ return [4 /*yield*/, this.connection.getMultipleAccountsInfo(accountArrays.map(function (item) { return item[1]; }))];
1029
1046
  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));
1047
+ response = _b.sent();
1048
+ for (i = 0; i < response.length; i++) {
1049
+ if (!response[i]) {
1050
+ ixs.push((0, spl_token_2.createAssociatedTokenAccountInstruction)(invoker.publicKey, accountArrays[i][0], accountArrays[i][1], data.mint, spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID));
1051
+ }
1033
1052
  }
1034
1053
  return [2 /*return*/];
1035
1054
  }
@@ -16,6 +16,7 @@ export interface ICreateStreamSolanaExt {
16
16
  }
17
17
  export interface IInteractStreamSolanaExt {
18
18
  invoker: SignerWalletAdapter | Keypair;
19
+ checkTokenAccounts?: boolean;
19
20
  }
20
21
  export interface ITopUpStreamSolanaExt {
21
22
  invoker: SignerWalletAdapter | Keypair;
@@ -280,9 +281,15 @@ export interface CreateMultipleStreamsValues {
280
281
  referral: string;
281
282
  recipients: Recipient[];
282
283
  }
283
- export interface CheckAssociatedTokenAccountData {
284
+ export interface CheckAssociatedTokenAccountsData {
285
+ sender: PublicKey;
286
+ senderTokens: PublicKey;
284
287
  recipient: PublicKey;
285
288
  recipientTokens: PublicKey;
289
+ partner: PublicKey;
290
+ partnerTokens: PublicKey;
291
+ streamflowTreasury: PublicKey;
292
+ streamflowTreasuryTokens: PublicKey;
286
293
  mint: PublicKey;
287
294
  }
288
295
  export interface BatchItem {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "5.9.0",
3
+ "version": "5.9.1",
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": "977658bcb7bb376fe528c69e2240a77cdb0bd1c3",
14
+ "gitHead": "58212d247d2d6648d10e8d78a9b1860d92fcfbd3",
15
15
  "devDependencies": {
16
16
  "@types/bn.js": "5.1.1",
17
17
  "@types/ethereum-checksum-address": "^0.0.0",