@streamflow/stream 3.0.16 → 4.0.0-Alpha.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.
Files changed (49) hide show
  1. package/dist/__tests__/aptos/streamClient.spec.d.ts +1 -0
  2. package/dist/__tests__/aptos/streamClient.spec.js +160 -0
  3. package/dist/aptos/StreamClient.d.ts +20 -0
  4. package/dist/aptos/StreamClient.js +297 -0
  5. package/dist/aptos/constants.d.ts +2 -0
  6. package/dist/aptos/constants.js +12 -0
  7. package/dist/aptos/index.d.ts +2 -0
  8. package/dist/aptos/index.js +23 -0
  9. package/dist/aptos/types.d.ts +10 -0
  10. package/dist/aptos/types.js +2 -0
  11. package/dist/common/StreamClient.d.ts +10 -0
  12. package/dist/common/StreamClient.js +9 -0
  13. package/dist/common/types.d.ts +61 -0
  14. package/dist/common/types.js +23 -0
  15. package/dist/{utils.d.ts → common/utils.d.ts} +0 -4
  16. package/dist/common/utils.js +31 -0
  17. package/dist/index.d.ts +4 -6
  18. package/dist/index.js +17 -13
  19. package/dist/{StreamClient.d.ts → solana/StreamClient.d.ts} +17 -17
  20. package/dist/{StreamClient.js → solana/StreamClient.js} +245 -309
  21. package/dist/{constants.d.ts → solana/constants.d.ts} +1 -1
  22. package/dist/{constants.js → solana/constants.js} +5 -5
  23. package/dist/solana/index.d.ts +7 -0
  24. package/dist/solana/index.js +42 -0
  25. package/dist/solana/instructionTypes.d.ts +81 -0
  26. package/dist/solana/instructionTypes.js +2 -0
  27. package/dist/{instructions.d.ts → solana/instructions.d.ts} +0 -2
  28. package/dist/{instructions.js → solana/instructions.js} +23 -38
  29. package/dist/solana/layout.d.ts +22 -0
  30. package/dist/{layout.js → solana/layout.js} +27 -2
  31. package/dist/{idl/timelock.d.ts → solana/timelockIDL.d.ts} +0 -0
  32. package/dist/{idl/timelock.js → solana/timelockIDL.js} +0 -0
  33. package/dist/{types.d.ts → solana/types.d.ts} +37 -34
  34. package/dist/{types.js → solana/types.js} +3 -20
  35. package/dist/solana/utils.d.ts +42 -0
  36. package/dist/solana/utils.js +269 -0
  37. package/package.json +24 -11
  38. package/dist/Stream.d.ts +0 -87
  39. package/dist/Stream.js +0 -503
  40. package/dist/__tests__/test_dependencies/airdrop/airdrop-request.d.ts +0 -3
  41. package/dist/__tests__/test_dependencies/airdrop/airdrop-request.js +0 -67
  42. package/dist/__tests__/test_dependencies/airdrop/airdrop.d.ts +0 -6
  43. package/dist/__tests__/test_dependencies/airdrop/airdrop.js +0 -215
  44. package/dist/__tests__/test_dependencies/constants/index.d.ts +0 -122
  45. package/dist/__tests__/test_dependencies/constants/index.js +0 -158
  46. package/dist/__tests__/test_dependencies/idl/airdrop.d.ts +0 -27
  47. package/dist/__tests__/test_dependencies/idl/airdrop.js +0 -171
  48. package/dist/layout.d.ts +0 -22
  49. package/dist/utils.js +0 -126
@@ -1,5 +1,20 @@
1
1
  "use strict";
2
2
  // Latest version of the SDK that does not use Anchor. It supports raw instructions.
3
+ var __extends = (this && this.__extends) || (function () {
4
+ var extendStatics = function (d, b) {
5
+ extendStatics = Object.setPrototypeOf ||
6
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
+ return extendStatics(d, b);
9
+ };
10
+ return function (d, b) {
11
+ if (typeof b !== "function" && b !== null)
12
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
+ extendStatics(d, b);
14
+ function __() { this.constructor = d; }
15
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
+ };
17
+ })();
3
18
  var __assign = (this && this.__assign) || function () {
4
19
  __assign = Object.assign || function(t) {
5
20
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -89,42 +104,43 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
89
104
  Object.defineProperty(exports, "__esModule", { value: true });
90
105
  var bn_js_1 = __importDefault(require("bn.js"));
91
106
  var buffer_1 = require("buffer");
92
- var anchor_1 = require("@project-serum/anchor");
107
+ var bs58_1 = __importDefault(require("bs58"));
93
108
  var spl_token_1 = require("@solana/spl-token");
94
109
  var web3_js_1 = require("@solana/web3.js");
95
110
  var types_1 = require("./types");
96
111
  var utils_1 = require("./utils");
97
112
  var constants_1 = require("./constants");
98
113
  var instructions_1 = require("./instructions");
99
- var bs58_1 = require("@project-serum/anchor/dist/cjs/utils/bytes/bs58");
114
+ var types_2 = require("../common/types");
115
+ var StreamClient_1 = require("../common/StreamClient");
100
116
  var METADATA_ACC_SIZE = 1104;
101
- var StreamClient = /** @class */ (function () {
117
+ var SolanaStreamClient = /** @class */ (function (_super) {
118
+ __extends(SolanaStreamClient, _super);
102
119
  /**
103
120
  * Create Stream instance
104
121
  */
105
- function StreamClient(clusterUrl, cluster, commitment, programId) {
106
- if (cluster === void 0) { cluster = types_1.Cluster.Mainnet; }
122
+ function SolanaStreamClient(clusterUrl, cluster, commitment, programId) {
123
+ if (cluster === void 0) { cluster = types_2.ICluster.Mainnet; }
107
124
  if (commitment === void 0) { commitment = "confirmed"; }
108
125
  if (programId === void 0) { programId = ""; }
109
- this.commitment = commitment;
110
- this.cluster = cluster;
111
- this.connection = new web3_js_1.Connection(clusterUrl, this.commitment);
112
- this.programId = new web3_js_1.PublicKey(constants_1.PROGRAM_ID[cluster]);
113
- if (programId != "") {
114
- this.programId = new web3_js_1.PublicKey(programId);
115
- }
126
+ var _this = _super.call(this) || this;
127
+ _this.commitment = commitment;
128
+ _this.connection = new web3_js_1.Connection(clusterUrl, _this.commitment);
129
+ _this.programId =
130
+ programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_1.PROGRAM_ID[cluster]);
131
+ return _this;
116
132
  }
117
- StreamClient.prototype.getConnection = function () {
133
+ SolanaStreamClient.prototype.getConnection = function () {
118
134
  return this.connection;
119
135
  };
120
- StreamClient.prototype.getProgramId = function () {
136
+ SolanaStreamClient.prototype.getProgramId = function () {
121
137
  return this.programId.toBase58();
122
138
  };
123
139
  /**
124
140
  * Creates a new stream/vesting contract.
125
141
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
126
142
  * @param {CreateParams} data
127
- * @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
143
+ * @param {WalletAdapter | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
128
144
  * @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
129
145
  * @param {string} data.mint - SPL Token mint.
130
146
  * @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
@@ -144,46 +160,48 @@ var StreamClient = /** @class */ (function () {
144
160
  * @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
145
161
  * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
146
162
  */
147
- StreamClient.prototype.create = function (_a) {
148
- var sender = _a.sender, recipient = _a.recipient, mint = _a.mint, start = _a.start, depositedAmount = _a.depositedAmount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _b = _a.automaticWithdrawal, automaticWithdrawal = _b === void 0 ? false : _b, _c = _a.withdrawalFrequency, withdrawalFrequency = _c === void 0 ? 0 : _c, _d = _a.partner, partner = _d === void 0 ? null : _d, _e = _a.isNative, isNative = _e === void 0 ? false : _e;
163
+ SolanaStreamClient.prototype.create = function (_a, _b) {
164
+ var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d;
165
+ var sender = _b.sender, _e = _b.partner, partner = _e === void 0 ? null : _e, _f = _b.isNative, isNative = _f === void 0 ? false : _f;
149
166
  return __awaiter(this, void 0, void 0, function () {
150
- var ixs, mintPublicKey, recipientPublicKey, metadata, _f, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, nativeInstructions, _g, commitment, hash, tx, signature;
151
- var _h;
152
- return __generator(this, function (_j) {
153
- switch (_j.label) {
167
+ var ixs, mintPublicKey, recipientPublicKey, metadata, _g, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, nativeInstructions, _h, commitment, hash, tx, signature;
168
+ var _j;
169
+ return __generator(this, function (_k) {
170
+ switch (_k.label) {
154
171
  case 0:
172
+ if (!sender.publicKey) {
173
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
174
+ }
155
175
  ixs = [];
156
176
  mintPublicKey = isNative ? new web3_js_1.PublicKey(mint) : spl_token_1.NATIVE_MINT;
157
177
  recipientPublicKey = new web3_js_1.PublicKey(recipient);
158
178
  metadata = web3_js_1.Keypair.generate();
159
179
  return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
160
180
  case 1:
161
- _f = __read.apply(void 0, [_j.sent(), 1]), escrowTokens = _f[0];
162
- return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
181
+ _g = __read.apply(void 0, [_k.sent(), 1]), escrowTokens = _g[0];
182
+ return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
163
183
  case 2:
164
- senderTokens = _j.sent();
165
- return [4 /*yield*/, ata(mintPublicKey, recipientPublicKey)];
184
+ senderTokens = _k.sent();
185
+ return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
166
186
  case 3:
167
- recipientTokens = _j.sent();
168
- return [4 /*yield*/, ata(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
187
+ recipientTokens = _k.sent();
188
+ return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
169
189
  case 4:
170
- streamflowTreasuryTokens = _j.sent();
171
- partnerPublicKey = partner
172
- ? new web3_js_1.PublicKey(partner)
173
- : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
174
- return [4 /*yield*/, ata(mintPublicKey, partnerPublicKey)];
190
+ streamflowTreasuryTokens = _k.sent();
191
+ partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
192
+ return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
175
193
  case 5:
176
- partnerTokens = _j.sent();
194
+ partnerTokens = _k.sent();
177
195
  if (!isNative) return [3 /*break*/, 7];
178
196
  return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
179
197
  case 6:
180
- _g = _j.sent();
198
+ _h = _k.sent();
181
199
  return [3 /*break*/, 8];
182
200
  case 7:
183
- _g = [];
184
- _j.label = 8;
201
+ _h = [];
202
+ _k.label = 8;
185
203
  case 8:
186
- nativeInstructions = _g;
204
+ nativeInstructions = _h;
187
205
  ixs.push((0, instructions_1.createStreamInstruction)({
188
206
  start: new bn_js_1.default(start),
189
207
  depositedAmount: depositedAmount,
@@ -219,21 +237,19 @@ var StreamClient = /** @class */ (function () {
219
237
  withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
220
238
  systemProgram: web3_js_1.SystemProgram.programId,
221
239
  }));
222
- commitment = typeof this.commitment == "string"
223
- ? this.commitment
224
- : this.commitment.commitment;
240
+ commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
225
241
  return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
226
242
  case 9:
227
- hash = _j.sent();
228
- tx = (_h = new web3_js_1.Transaction({
243
+ hash = _k.sent();
244
+ tx = (_j = new web3_js_1.Transaction({
229
245
  feePayer: sender.publicKey,
230
246
  blockhash: hash.blockhash,
231
247
  lastValidBlockHeight: hash.lastValidBlockHeight,
232
- })).add.apply(_h, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
248
+ })).add.apply(_j, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
233
249
  tx.partialSign(metadata);
234
250
  return [4 /*yield*/, this.sign(sender, tx, hash)];
235
251
  case 10:
236
- signature = _j.sent();
252
+ signature = _k.sent();
237
253
  return [2 /*return*/, { ixs: ixs, tx: signature, metadata: metadata }];
238
254
  }
239
255
  });
@@ -268,22 +284,26 @@ var StreamClient = /** @class */ (function () {
268
284
  * @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
269
285
  * @param {number} [data.withdrawalFrequency = 0] - Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
270
286
  * @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
271
- * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
287
+ * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
272
288
  */
273
- StreamClient.prototype.createUnchecked = function (_a) {
274
- var sender = _a.sender, recipient = _a.recipient, mint = _a.mint, start = _a.start, depositedAmount = _a.depositedAmount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _b = _a.automaticWithdrawal, automaticWithdrawal = _b === void 0 ? false : _b, _c = _a.withdrawalFrequency, withdrawalFrequency = _c === void 0 ? 0 : _c, _d = _a.partner, partner = _d === void 0 ? null : _d, _e = _a.isNative, isNative = _e === void 0 ? false : _e;
289
+ SolanaStreamClient.prototype.createUnchecked = function (_a, _b) {
290
+ var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d;
291
+ var sender = _b.sender, _e = _b.partner, partner = _e === void 0 ? null : _e, _f = _b.isNative, isNative = _f === void 0 ? false : _f;
275
292
  return __awaiter(this, void 0, void 0, function () {
276
- var mintPublicKey, recipientPublicKey, metadata, rentToExempt, createMetadataInstruction, _f, escrowTokens, senderTokens, partnerPublicKey, nativeInstructions, _g, createInstruction, commitment, ixs, hash, tx, signature;
277
- var _h;
278
- return __generator(this, function (_j) {
279
- switch (_j.label) {
293
+ var mintPublicKey, recipientPublicKey, metadata, rentToExempt, createMetadataInstruction, _g, escrowTokens, senderTokens, partnerPublicKey, nativeInstructions, _h, createInstruction, commitment, ixs, hash, tx, signature;
294
+ var _j;
295
+ return __generator(this, function (_k) {
296
+ switch (_k.label) {
280
297
  case 0:
298
+ if (!sender.publicKey) {
299
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
300
+ }
281
301
  mintPublicKey = new web3_js_1.PublicKey(mint);
282
302
  recipientPublicKey = new web3_js_1.PublicKey(recipient);
283
303
  metadata = web3_js_1.Keypair.generate();
284
304
  return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
285
305
  case 1:
286
- rentToExempt = _j.sent();
306
+ rentToExempt = _k.sent();
287
307
  createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
288
308
  programId: this.programId,
289
309
  space: METADATA_ACC_SIZE,
@@ -293,23 +313,21 @@ var StreamClient = /** @class */ (function () {
293
313
  });
294
314
  return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
295
315
  case 2:
296
- _f = __read.apply(void 0, [_j.sent(), 1]), escrowTokens = _f[0];
297
- return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
316
+ _g = __read.apply(void 0, [_k.sent(), 1]), escrowTokens = _g[0];
317
+ return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
298
318
  case 3:
299
- senderTokens = _j.sent();
300
- partnerPublicKey = partner
301
- ? new web3_js_1.PublicKey(partner)
302
- : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
319
+ senderTokens = _k.sent();
320
+ partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
303
321
  if (!isNative) return [3 /*break*/, 5];
304
322
  return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
305
323
  case 4:
306
- _g = _j.sent();
324
+ _h = _k.sent();
307
325
  return [3 /*break*/, 6];
308
326
  case 5:
309
- _g = [];
310
- _j.label = 6;
327
+ _h = [];
328
+ _k.label = 6;
311
329
  case 6:
312
- nativeInstructions = _g;
330
+ nativeInstructions = _h;
313
331
  createInstruction = (0, instructions_1.createUncheckedStreamInstruction)({
314
332
  start: new bn_js_1.default(start),
315
333
  depositedAmount: depositedAmount,
@@ -340,25 +358,20 @@ var StreamClient = /** @class */ (function () {
340
358
  withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
341
359
  systemProgram: web3_js_1.SystemProgram.programId,
342
360
  });
343
- commitment = typeof this.commitment == "string"
344
- ? this.commitment
345
- : this.commitment.commitment;
346
- ixs = [
347
- createMetadataInstruction,
348
- createInstruction,
349
- ];
361
+ commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
362
+ ixs = [createMetadataInstruction, createInstruction];
350
363
  return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
351
364
  case 7:
352
- hash = _j.sent();
353
- tx = (_h = new web3_js_1.Transaction({
365
+ hash = _k.sent();
366
+ tx = (_j = new web3_js_1.Transaction({
354
367
  feePayer: sender.publicKey,
355
368
  blockhash: hash.blockhash,
356
369
  lastValidBlockHeight: hash.lastValidBlockHeight,
357
- })).add.apply(_h, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
370
+ })).add.apply(_j, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
358
371
  tx.partialSign(metadata);
359
372
  return [4 /*yield*/, this.sign(sender, tx, hash)];
360
373
  case 8:
361
- signature = _j.sent();
374
+ signature = _k.sent();
362
375
  return [2 /*return*/, { ixs: ixs, tx: signature, metadata: metadata }];
363
376
  }
364
377
  });
@@ -384,89 +397,92 @@ var StreamClient = /** @class */ (function () {
384
397
  * @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
385
398
  * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
386
399
  */
387
- StreamClient.prototype.createMultiple = function (data) {
400
+ SolanaStreamClient.prototype.createMultiple = function (data, _a) {
401
+ var sender = _a.sender, _b = _a.partner, partner = _b === void 0 ? null : _b, _c = _a.isNative, isNative = _c === void 0 ? false : _c;
388
402
  return __awaiter(this, void 0, void 0, function () {
389
- var sender, recipientsData, metadatas, metadataToRecipient, errors, signatures, batch, recipientsData_1, recipientsData_1_1, recipientData, _a, tx, metadata, metadataPubKey, e_1_1, totalDepositedAmount, nativeInstructions, commitment, hash, prepareTransaction, signed_batch, prepareTx, batchTransactionsCalls, responses, successes, failures;
390
- var e_1, _b, _c;
403
+ var recipients, metadatas, metadataToRecipient, errors, signatures, batch, recipients_1, recipients_1_1, recipientData, _d, tx, metadata, metadataPubKey, e_1_1, totalDepositedAmount, nativeInstructions, commitment, hash, prepareTransaction, signed_batch, prepareTx, batchTransactionsCalls, responses, successes, failures;
404
+ var e_1, _e, _f;
391
405
  var _this = this;
392
- return __generator(this, function (_d) {
393
- switch (_d.label) {
406
+ return __generator(this, function (_g) {
407
+ switch (_g.label) {
394
408
  case 0:
395
- sender = data.sender, recipientsData = data.recipientsData;
409
+ recipients = data.recipients;
410
+ if (!sender.publicKey) {
411
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
412
+ }
396
413
  metadatas = [];
397
414
  metadataToRecipient = {};
398
415
  errors = [];
399
416
  signatures = [];
400
417
  batch = [];
401
- _d.label = 1;
418
+ _g.label = 1;
402
419
  case 1:
403
- _d.trys.push([1, 6, 7, 8]);
404
- recipientsData_1 = __values(recipientsData), recipientsData_1_1 = recipientsData_1.next();
405
- _d.label = 2;
420
+ _g.trys.push([1, 6, 7, 8]);
421
+ recipients_1 = __values(recipients), recipients_1_1 = recipients_1.next();
422
+ _g.label = 2;
406
423
  case 2:
407
- if (!!recipientsData_1_1.done) return [3 /*break*/, 5];
408
- recipientData = recipientsData_1_1.value;
409
- return [4 /*yield*/, this.prepareStreamTransaction(recipientData, data)];
424
+ if (!!recipients_1_1.done) return [3 /*break*/, 5];
425
+ recipientData = recipients_1_1.value;
426
+ return [4 /*yield*/, this.prepareStreamTransaction(recipientData, data, {
427
+ sender: sender,
428
+ partner: partner,
429
+ })];
410
430
  case 3:
411
- _a = _d.sent(), tx = _a.tx, metadata = _a.metadata;
431
+ _d = _g.sent(), tx = _d.tx, metadata = _d.metadata;
412
432
  metadataPubKey = metadata.publicKey.toBase58();
413
433
  metadataToRecipient[metadataPubKey] = recipientData;
414
434
  metadatas.push(metadata);
415
435
  batch.push({ tx: tx, recipient: recipientData.recipient });
416
- _d.label = 4;
436
+ _g.label = 4;
417
437
  case 4:
418
- recipientsData_1_1 = recipientsData_1.next();
438
+ recipients_1_1 = recipients_1.next();
419
439
  return [3 /*break*/, 2];
420
440
  case 5: return [3 /*break*/, 8];
421
441
  case 6:
422
- e_1_1 = _d.sent();
442
+ e_1_1 = _g.sent();
423
443
  e_1 = { error: e_1_1 };
424
444
  return [3 /*break*/, 8];
425
445
  case 7:
426
446
  try {
427
- if (recipientsData_1_1 && !recipientsData_1_1.done && (_b = recipientsData_1.return)) _b.call(recipientsData_1);
447
+ if (recipients_1_1 && !recipients_1_1.done && (_e = recipients_1.return)) _e.call(recipients_1);
428
448
  }
429
449
  finally { if (e_1) throw e_1.error; }
430
450
  return [7 /*endfinally*/];
431
451
  case 8:
432
- if (!data.isNative) return [3 /*break*/, 11];
433
- totalDepositedAmount = recipientsData.reduce(function (acc, recipient) { return recipient.depositedAmount.add(acc); }, new bn_js_1.default(0));
452
+ if (!isNative) return [3 /*break*/, 11];
453
+ totalDepositedAmount = recipients.reduce(function (acc, recipient) { return recipient.amount.add(acc); }, new bn_js_1.default(0));
434
454
  return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
435
455
  case 9:
436
- nativeInstructions = _d.sent();
437
- commitment = typeof this.commitment == "string"
438
- ? this.commitment
439
- : this.commitment.commitment;
456
+ nativeInstructions = _g.sent();
457
+ commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
440
458
  return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
441
459
  case 10:
442
- hash = _d.sent();
443
- prepareTransaction = (_c = new web3_js_1.Transaction({
460
+ hash = _g.sent();
461
+ prepareTransaction = (_f = new web3_js_1.Transaction({
444
462
  feePayer: sender.publicKey,
445
463
  blockhash: hash.blockhash,
446
464
  lastValidBlockHeight: hash.lastValidBlockHeight,
447
- })).add.apply(_c, __spreadArray([], __read(nativeInstructions), false));
465
+ })).add.apply(_f, __spreadArray([], __read(nativeInstructions), false));
448
466
  batch.push({ tx: prepareTransaction, recipient: sender.publicKey.toBase58() });
449
- _d.label = 11;
450
- case 11: return [4 /*yield*/, signAllTransactionWithRecipients(sender, batch)];
467
+ _g.label = 11;
468
+ case 11: return [4 /*yield*/, (0, utils_1.signAllTransactionWithRecipients)(sender, batch)];
451
469
  case 12:
452
- signed_batch = _d.sent();
453
- if (!data.isNative) return [3 /*break*/, 14];
470
+ signed_batch = _g.sent();
471
+ if (!isNative) return [3 /*break*/, 14];
454
472
  prepareTx = signed_batch.pop();
455
- return [4 /*yield*/, sendAndConfirmStreamRawTransaction(this.connection, prepareTx)];
473
+ return [4 /*yield*/, (0, utils_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx)];
456
474
  case 13:
457
- _d.sent();
458
- _d.label = 14;
475
+ _g.sent();
476
+ _g.label = 14;
459
477
  case 14:
460
478
  batchTransactionsCalls = signed_batch.map(function (el) {
461
- return sendAndConfirmStreamRawTransaction(_this.connection, el);
479
+ return (0, utils_1.sendAndConfirmStreamRawTransaction)(_this.connection, el);
462
480
  });
463
481
  return [4 /*yield*/, Promise.allSettled(batchTransactionsCalls)];
464
482
  case 15:
465
- responses = _d.sent();
483
+ responses = _g.sent();
466
484
  successes = responses
467
- .filter(function (el) {
468
- return el.status === "fulfilled";
469
- })
485
+ .filter(function (el) { return el.status === "fulfilled"; })
470
486
  .map(function (el) { return el.value; });
471
487
  signatures.push.apply(signatures, __spreadArray([], __read(successes.map(function (el) { return el.signature; })), false));
472
488
  failures = responses
@@ -485,29 +501,33 @@ var StreamClient = /** @class */ (function () {
485
501
  * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be withdrawn from.
486
502
  * @param {BN} data.amount - Requested amount (in the smallest units) to withdraw (while streaming). If stream is completed, the whole amount will be withdrawn.
487
503
  */
488
- StreamClient.prototype.withdraw = function (_a) {
489
- var invoker = _a.invoker, id = _a.id, amount = _a.amount;
504
+ SolanaStreamClient.prototype.withdraw = function (_a, _b) {
505
+ var id = _a.id, amount = _a.amount;
506
+ var invoker = _b.invoker;
490
507
  return __awaiter(this, void 0, void 0, function () {
491
508
  var ixs, streamPublicKey, escrow, data, streamflowTreasuryTokens, partnerTokens, commitment, hash, tx, signature;
492
- var _b;
493
- return __generator(this, function (_c) {
494
- switch (_c.label) {
509
+ var _c;
510
+ return __generator(this, function (_d) {
511
+ switch (_d.label) {
495
512
  case 0:
513
+ if (!invoker.publicKey) {
514
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
515
+ }
496
516
  ixs = [];
497
517
  streamPublicKey = new web3_js_1.PublicKey(id);
498
518
  return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
499
519
  case 1:
500
- escrow = _c.sent();
520
+ escrow = _d.sent();
501
521
  if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
502
522
  throw new Error("Couldn't get account info");
503
523
  }
504
524
  data = (0, utils_1.decodeStream)(escrow.data);
505
- return [4 /*yield*/, ata(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
525
+ return [4 /*yield*/, (0, utils_1.ata)(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
506
526
  case 2:
507
- streamflowTreasuryTokens = _c.sent();
508
- return [4 /*yield*/, ata(data.mint, data.partner)];
527
+ streamflowTreasuryTokens = _d.sent();
528
+ return [4 /*yield*/, (0, utils_1.ata)(data.mint, data.partner)];
509
529
  case 3:
510
- partnerTokens = _c.sent();
530
+ partnerTokens = _d.sent();
511
531
  ixs.push((0, instructions_1.withdrawStreamInstruction)(amount, this.programId, {
512
532
  authority: invoker.publicKey,
513
533
  recipient: invoker.publicKey,
@@ -521,20 +541,18 @@ var StreamClient = /** @class */ (function () {
521
541
  mint: data.mint,
522
542
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
523
543
  }));
524
- commitment = typeof this.commitment == "string"
525
- ? this.commitment
526
- : this.commitment.commitment;
544
+ commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
527
545
  return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
528
546
  case 4:
529
- hash = _c.sent();
530
- tx = (_b = new web3_js_1.Transaction({
547
+ hash = _d.sent();
548
+ tx = (_c = new web3_js_1.Transaction({
531
549
  feePayer: invoker.publicKey,
532
550
  blockhash: hash.blockhash,
533
551
  lastValidBlockHeight: hash.lastValidBlockHeight,
534
- })).add.apply(_b, __spreadArray([], __read(ixs), false));
552
+ })).add.apply(_c, __spreadArray([], __read(ixs), false));
535
553
  return [4 /*yield*/, this.sign(invoker, tx, hash)];
536
554
  case 5:
537
- signature = _c.sent();
555
+ signature = _d.sent();
538
556
  return [2 /*return*/, { ixs: ixs, tx: signature }];
539
557
  }
540
558
  });
@@ -546,28 +564,32 @@ var StreamClient = /** @class */ (function () {
546
564
  * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
547
565
  * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be canceled.
548
566
  */
549
- StreamClient.prototype.cancel = function (_a) {
550
- var invoker = _a.invoker, id = _a.id;
567
+ SolanaStreamClient.prototype.cancel = function (_a, _b) {
568
+ var id = _a.id;
569
+ var invoker = _b.invoker;
551
570
  return __awaiter(this, void 0, void 0, function () {
552
571
  var streamPublicKey, escrow_acc, data, streamflowTreasuryTokens, partnerTokens, ixs, commitment, hash, tx, signature;
553
- var _b;
554
- return __generator(this, function (_c) {
555
- switch (_c.label) {
572
+ var _c;
573
+ return __generator(this, function (_d) {
574
+ switch (_d.label) {
556
575
  case 0:
576
+ if (!invoker.publicKey) {
577
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
578
+ }
557
579
  streamPublicKey = new web3_js_1.PublicKey(id);
558
580
  return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
559
581
  case 1:
560
- escrow_acc = _c.sent();
582
+ escrow_acc = _d.sent();
561
583
  if (!(escrow_acc === null || escrow_acc === void 0 ? void 0 : escrow_acc.data)) {
562
584
  throw new Error("Couldn't get account info");
563
585
  }
564
586
  data = (0, utils_1.decodeStream)(escrow_acc === null || escrow_acc === void 0 ? void 0 : escrow_acc.data);
565
- return [4 /*yield*/, ata(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
587
+ return [4 /*yield*/, (0, utils_1.ata)(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
566
588
  case 2:
567
- streamflowTreasuryTokens = _c.sent();
568
- return [4 /*yield*/, ata(data.mint, data.partner)];
589
+ streamflowTreasuryTokens = _d.sent();
590
+ return [4 /*yield*/, (0, utils_1.ata)(data.mint, data.partner)];
569
591
  case 3:
570
- partnerTokens = _c.sent();
592
+ partnerTokens = _d.sent();
571
593
  ixs = [];
572
594
  ixs.push((0, instructions_1.cancelStreamInstruction)(this.programId, {
573
595
  authority: invoker.publicKey,
@@ -584,20 +606,18 @@ var StreamClient = /** @class */ (function () {
584
606
  mint: data.mint,
585
607
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
586
608
  }));
587
- commitment = typeof this.commitment == "string"
588
- ? this.commitment
589
- : this.commitment.commitment;
609
+ commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
590
610
  return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
591
611
  case 4:
592
- hash = _c.sent();
593
- tx = (_b = new web3_js_1.Transaction({
612
+ hash = _d.sent();
613
+ tx = (_c = new web3_js_1.Transaction({
594
614
  feePayer: invoker.publicKey,
595
615
  blockhash: hash.blockhash,
596
616
  lastValidBlockHeight: hash.lastValidBlockHeight,
597
- })).add.apply(_b, __spreadArray([], __read(ixs), false));
617
+ })).add.apply(_c, __spreadArray([], __read(ixs), false));
598
618
  return [4 /*yield*/, this.sign(invoker, tx, hash)];
599
619
  case 5:
600
- signature = _c.sent();
620
+ signature = _d.sent();
601
621
  return [2 /*return*/, { ixs: ixs, tx: signature }];
602
622
  }
603
623
  });
@@ -611,27 +631,31 @@ var StreamClient = /** @class */ (function () {
611
631
  * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be transferred.
612
632
  * @param {string} data.recipientId - Address of a new recipient.
613
633
  */
614
- StreamClient.prototype.transfer = function (_a) {
615
- var invoker = _a.invoker, id = _a.id, recipientId = _a.recipientId;
634
+ SolanaStreamClient.prototype.transfer = function (_a, _b) {
635
+ var id = _a.id, newRecipientString = _a.newRecipient;
636
+ var invoker = _b.invoker;
616
637
  return __awaiter(this, void 0, void 0, function () {
617
638
  var ixs, stream, newRecipient, escrow, mint, newRecipientTokens, commitment, hash, tx, signature;
618
- var _b;
619
- return __generator(this, function (_c) {
620
- switch (_c.label) {
639
+ var _c;
640
+ return __generator(this, function (_d) {
641
+ switch (_d.label) {
621
642
  case 0:
643
+ if (!invoker.publicKey) {
644
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
645
+ }
622
646
  ixs = [];
623
647
  stream = new web3_js_1.PublicKey(id);
624
- newRecipient = new web3_js_1.PublicKey(recipientId);
648
+ newRecipient = new web3_js_1.PublicKey(newRecipientString);
625
649
  return [4 /*yield*/, this.connection.getAccountInfo(stream)];
626
650
  case 1:
627
- escrow = _c.sent();
651
+ escrow = _d.sent();
628
652
  if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
629
653
  throw new Error("Couldn't get account info");
630
654
  }
631
655
  mint = (0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data).mint;
632
- return [4 /*yield*/, ata(mint, newRecipient)];
656
+ return [4 /*yield*/, (0, utils_1.ata)(mint, newRecipient)];
633
657
  case 2:
634
- newRecipientTokens = _c.sent();
658
+ newRecipientTokens = _d.sent();
635
659
  ixs.push((0, instructions_1.transferStreamInstruction)(this.programId, {
636
660
  authority: invoker.publicKey,
637
661
  newRecipient: newRecipient,
@@ -643,20 +667,18 @@ var StreamClient = /** @class */ (function () {
643
667
  associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
644
668
  systemProgram: web3_js_1.SystemProgram.programId,
645
669
  }));
646
- commitment = typeof this.commitment == "string"
647
- ? this.commitment
648
- : this.commitment.commitment;
670
+ commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
649
671
  return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
650
672
  case 3:
651
- hash = _c.sent();
652
- tx = (_b = new web3_js_1.Transaction({
673
+ hash = _d.sent();
674
+ tx = (_c = new web3_js_1.Transaction({
653
675
  feePayer: invoker.publicKey,
654
676
  blockhash: hash.blockhash,
655
677
  lastValidBlockHeight: hash.lastValidBlockHeight,
656
- })).add.apply(_b, __spreadArray([], __read(ixs), false));
678
+ })).add.apply(_c, __spreadArray([], __read(ixs), false));
657
679
  return [4 /*yield*/, this.sign(invoker, tx, hash)];
658
680
  case 4:
659
- signature = _c.sent();
681
+ signature = _d.sent();
660
682
  return [2 /*return*/, { ixs: ixs, tx: signature }];
661
683
  }
662
684
  });
@@ -669,39 +691,43 @@ var StreamClient = /** @class */ (function () {
669
691
  * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be topped up.
670
692
  * @param {BN} data.amount - Specified amount (in the smallest units) to topup (increases deposited amount).
671
693
  */
672
- StreamClient.prototype.topup = function (_a) {
673
- var invoker = _a.invoker, id = _a.id, amount = _a.amount, isNative = _a.isNative;
694
+ SolanaStreamClient.prototype.topup = function (_a, _b) {
695
+ var id = _a.id, amount = _a.amount;
696
+ var invoker = _b.invoker, isNative = _b.isNative;
674
697
  return __awaiter(this, void 0, void 0, function () {
675
- var ixs, streamPublicKey, escrow, _b, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, nativeInstructions, _c, commitment, hash, tx, signature;
676
- var _d;
677
- return __generator(this, function (_e) {
678
- switch (_e.label) {
698
+ var ixs, streamPublicKey, escrow, _c, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, nativeInstructions, _d, commitment, hash, tx, signature;
699
+ var _e;
700
+ return __generator(this, function (_f) {
701
+ switch (_f.label) {
679
702
  case 0:
703
+ if (!invoker.publicKey) {
704
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
705
+ }
680
706
  ixs = [];
681
707
  streamPublicKey = new web3_js_1.PublicKey(id);
682
708
  return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
683
709
  case 1:
684
- escrow = _e.sent();
710
+ escrow = _f.sent();
685
711
  if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
686
712
  throw new Error("Couldn't get account info");
687
713
  }
688
- _b = (0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data), mint = _b.mint, partner = _b.partner, senderTokens = _b.senderTokens, escrowTokens = _b.escrowTokens;
689
- return [4 /*yield*/, ata(mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
714
+ _c = (0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data), mint = _c.mint, partner = _c.partner, senderTokens = _c.senderTokens, escrowTokens = _c.escrowTokens;
715
+ return [4 /*yield*/, (0, utils_1.ata)(mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
690
716
  case 2:
691
- streamflowTreasuryTokens = _e.sent();
692
- return [4 /*yield*/, ata(mint, partner)];
717
+ streamflowTreasuryTokens = _f.sent();
718
+ return [4 /*yield*/, (0, utils_1.ata)(mint, partner)];
693
719
  case 3:
694
- partnerTokens = _e.sent();
720
+ partnerTokens = _f.sent();
695
721
  if (!isNative) return [3 /*break*/, 5];
696
722
  return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, invoker.publicKey, amount)];
697
723
  case 4:
698
- _c = _e.sent();
724
+ _d = _f.sent();
699
725
  return [3 /*break*/, 6];
700
726
  case 5:
701
- _c = [];
702
- _e.label = 6;
727
+ _d = [];
728
+ _f.label = 6;
703
729
  case 6:
704
- nativeInstructions = _c;
730
+ nativeInstructions = _d;
705
731
  ixs.push((0, instructions_1.topupStreamInstruction)(amount, this.programId, {
706
732
  sender: invoker.publicKey,
707
733
  senderTokens: senderTokens,
@@ -716,20 +742,18 @@ var StreamClient = /** @class */ (function () {
716
742
  withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
717
743
  systemProgram: web3_js_1.SystemProgram.programId,
718
744
  }));
719
- commitment = typeof this.commitment == "string"
720
- ? this.commitment
721
- : this.commitment.commitment;
745
+ commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
722
746
  return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
723
747
  case 7:
724
- hash = _e.sent();
725
- tx = (_d = new web3_js_1.Transaction({
748
+ hash = _f.sent();
749
+ tx = (_e = new web3_js_1.Transaction({
726
750
  feePayer: invoker.publicKey,
727
751
  blockhash: hash.blockhash,
728
752
  lastValidBlockHeight: hash.lastValidBlockHeight,
729
- })).add.apply(_d, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
753
+ })).add.apply(_e, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
730
754
  return [4 /*yield*/, this.sign(invoker, tx, hash)];
731
755
  case 8:
732
- signature = _e.sent();
756
+ signature = _f.sent();
733
757
  return [2 /*return*/, { ixs: ixs, tx: signature }];
734
758
  }
735
759
  });
@@ -739,14 +763,15 @@ var StreamClient = /** @class */ (function () {
739
763
  * Fetch stream data by its id (address).
740
764
  * @param {string} id - Identifier of a stream that is fetched.
741
765
  */
742
- StreamClient.prototype.getOne = function (id) {
766
+ SolanaStreamClient.prototype.getOne = function (_a) {
767
+ var id = _a.id;
743
768
  return __awaiter(this, void 0, void 0, function () {
744
769
  var escrow;
745
- return __generator(this, function (_a) {
746
- switch (_a.label) {
770
+ return __generator(this, function (_b) {
771
+ switch (_b.label) {
747
772
  case 0: return [4 /*yield*/, this.connection.getAccountInfo(new web3_js_1.PublicKey(id), constants_1.TX_FINALITY_CONFIRMED)];
748
773
  case 1:
749
- escrow = _a.sent();
774
+ escrow = _b.sent();
750
775
  if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
751
776
  throw new Error("Couldn't get account info.");
752
777
  }
@@ -763,8 +788,8 @@ var StreamClient = /** @class */ (function () {
763
788
  * @param {StreamType} [data.type = StreamType.All] - It can be one of: stream, vesting, all.
764
789
  * @param {StreamDirection} [data.direction = StreamDirection.All] - It can be one of: incoming, outgoing, all.
765
790
  */
766
- StreamClient.prototype.get = function (_a) {
767
- var wallet = _a.wallet, _b = _a.type, type = _b === void 0 ? types_1.StreamType.All : _b, _c = _a.direction, direction = _c === void 0 ? types_1.StreamDirection.All : _c;
791
+ SolanaStreamClient.prototype.get = function (_a) {
792
+ var wallet = _a.wallet, _b = _a.type, type = _b === void 0 ? types_2.StreamType.All : _b, _c = _a.direction, direction = _c === void 0 ? types_2.StreamDirection.All : _c;
768
793
  return __awaiter(this, void 0, void 0, function () {
769
794
  var accounts, outgoingAccounts, incomingAccounts, offset, streams, sortedStreams;
770
795
  return __generator(this, function (_d) {
@@ -772,19 +797,17 @@ var StreamClient = /** @class */ (function () {
772
797
  case 0:
773
798
  accounts = [];
774
799
  if (!(direction === "all")) return [3 /*break*/, 3];
775
- return [4 /*yield*/, getProgramAccounts(this.connection, wallet, constants_1.STREAM_STRUCT_OFFSET_SENDER, this.programId)];
800
+ return [4 /*yield*/, (0, utils_1.getProgramAccounts)(this.connection, wallet, constants_1.STREAM_STRUCT_OFFSET_SENDER, this.programId)];
776
801
  case 1:
777
802
  outgoingAccounts = _d.sent();
778
- return [4 /*yield*/, getProgramAccounts(this.connection, wallet, constants_1.STREAM_STRUCT_OFFSET_RECIPIENT, this.programId)];
803
+ return [4 /*yield*/, (0, utils_1.getProgramAccounts)(this.connection, wallet, constants_1.STREAM_STRUCT_OFFSET_RECIPIENT, this.programId)];
779
804
  case 2:
780
805
  incomingAccounts = _d.sent();
781
806
  accounts = __spreadArray(__spreadArray([], __read(outgoingAccounts), false), __read(incomingAccounts), false);
782
807
  return [3 /*break*/, 5];
783
808
  case 3:
784
- offset = direction === "outgoing"
785
- ? constants_1.STREAM_STRUCT_OFFSET_SENDER
786
- : constants_1.STREAM_STRUCT_OFFSET_RECIPIENT;
787
- return [4 /*yield*/, getProgramAccounts(this.connection, wallet, offset, this.programId)];
809
+ offset = direction === "outgoing" ? constants_1.STREAM_STRUCT_OFFSET_SENDER : constants_1.STREAM_STRUCT_OFFSET_RECIPIENT;
810
+ return [4 /*yield*/, (0, utils_1.getProgramAccounts)(this.connection, wallet, offset, this.programId)];
788
811
  case 4:
789
812
  accounts = _d.sent();
790
813
  _d.label = 5;
@@ -809,13 +832,13 @@ var StreamClient = /** @class */ (function () {
809
832
  });
810
833
  });
811
834
  };
812
- StreamClient.prototype.sign = function (invoker, tx, hash) {
835
+ SolanaStreamClient.prototype.sign = function (invoker, tx, hash) {
813
836
  return __awaiter(this, void 0, void 0, function () {
814
837
  var rawTx, confirmationStrategy, signature;
815
838
  return __generator(this, function (_a) {
816
839
  switch (_a.label) {
817
840
  case 0:
818
- if (!isAnchorWallet(invoker)) return [3 /*break*/, 2];
841
+ if (!(0, utils_1.isSignerWallet)(invoker)) return [3 /*break*/, 2];
819
842
  return [4 /*yield*/, invoker.signTransaction(tx)];
820
843
  case 1:
821
844
  _a.sent();
@@ -829,7 +852,7 @@ var StreamClient = /** @class */ (function () {
829
852
  throw Error("Error with transaction parameters.");
830
853
  confirmationStrategy = {
831
854
  lastValidBlockHeight: hash.lastValidBlockHeight,
832
- signature: (0, bs58_1.encode)(tx.signature),
855
+ signature: bs58_1.default.encode(tx.signature),
833
856
  blockhash: hash.blockhash,
834
857
  };
835
858
  return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, rawTx, confirmationStrategy)];
@@ -845,42 +868,40 @@ var StreamClient = /** @class */ (function () {
845
868
  * @param {MultiRecipient} recipient - Wallet sending stream to
846
869
  * @param {CreateMultiParams} streamParams - Parameters of stream user wants to create.
847
870
  */
848
- StreamClient.prototype.prepareStreamTransaction = function (recipient, streamParams) {
871
+ SolanaStreamClient.prototype.prepareStreamTransaction = function (recipient, streamParams, solanaExtendedConfig) {
849
872
  return __awaiter(this, void 0, void 0, function () {
850
- var sender, mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, _c, partner, ixs, commitment, recipientPublicKey, mintPublicKey, metadata, _d, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, hash, tx;
873
+ var mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, sender, _c, partner, ixs, commitment, recipientPublicKey, mintPublicKey, metadata, _d, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, hash, tx;
851
874
  var _e;
852
875
  return __generator(this, function (_f) {
853
876
  switch (_f.label) {
854
877
  case 0:
855
- sender = streamParams.sender, mint = streamParams.mint, start = streamParams.start, period = streamParams.period, cliff = streamParams.cliff, canTopup = streamParams.canTopup, cancelableBySender = streamParams.cancelableBySender, cancelableByRecipient = streamParams.cancelableByRecipient, transferableBySender = streamParams.transferableBySender, transferableByRecipient = streamParams.transferableByRecipient, _a = streamParams.automaticWithdrawal, automaticWithdrawal = _a === void 0 ? false : _a, _b = streamParams.withdrawalFrequency, withdrawalFrequency = _b === void 0 ? 0 : _b, _c = streamParams.partner, partner = _c === void 0 ? null : _c;
878
+ mint = streamParams.tokenId, start = streamParams.start, period = streamParams.period, cliff = streamParams.cliff, canTopup = streamParams.canTopup, cancelableBySender = streamParams.cancelableBySender, cancelableByRecipient = streamParams.cancelableByRecipient, transferableBySender = streamParams.transferableBySender, transferableByRecipient = streamParams.transferableByRecipient, _a = streamParams.automaticWithdrawal, automaticWithdrawal = _a === void 0 ? false : _a, _b = streamParams.withdrawalFrequency, withdrawalFrequency = _b === void 0 ? 0 : _b;
879
+ sender = solanaExtendedConfig.sender, _c = solanaExtendedConfig.partner, partner = _c === void 0 ? null : _c;
880
+ if (!sender.publicKey) {
881
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
882
+ }
856
883
  ixs = [];
857
- commitment = typeof this.commitment == "string"
858
- ? this.commitment
859
- : this.commitment.commitment;
884
+ commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
860
885
  recipientPublicKey = new web3_js_1.PublicKey(recipient.recipient);
861
886
  mintPublicKey = new web3_js_1.PublicKey(mint);
862
887
  metadata = web3_js_1.Keypair.generate();
863
- return [4 /*yield*/, anchor_1.web3.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
888
+ _d = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId), 1), escrowTokens = _d[0];
889
+ return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
864
890
  case 1:
865
- _d = __read.apply(void 0, [_f.sent(), 1]), escrowTokens = _d[0];
866
- return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
867
- case 2:
868
891
  senderTokens = _f.sent();
869
- return [4 /*yield*/, ata(mintPublicKey, recipientPublicKey)];
870
- case 3:
892
+ return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
893
+ case 2:
871
894
  recipientTokens = _f.sent();
872
- return [4 /*yield*/, ata(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
873
- case 4:
895
+ return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
896
+ case 3:
874
897
  streamflowTreasuryTokens = _f.sent();
875
- partnerPublicKey = partner
876
- ? new web3_js_1.PublicKey(partner)
877
- : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
878
- return [4 /*yield*/, ata(mintPublicKey, partnerPublicKey)];
879
- case 5:
898
+ partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
899
+ return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
900
+ case 4:
880
901
  partnerTokens = _f.sent();
881
902
  ixs.push((0, instructions_1.createStreamInstruction)({
882
903
  start: new bn_js_1.default(start),
883
- depositedAmount: recipient.depositedAmount,
904
+ depositedAmount: recipient.amount,
884
905
  period: new bn_js_1.default(period),
885
906
  amountPerPeriod: recipient.amountPerPeriod,
886
907
  cliff: new bn_js_1.default(cliff),
@@ -914,7 +935,7 @@ var StreamClient = /** @class */ (function () {
914
935
  systemProgram: web3_js_1.SystemProgram.programId,
915
936
  }));
916
937
  return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
917
- case 6:
938
+ case 5:
918
939
  hash = _f.sent();
919
940
  tx = (_e = new web3_js_1.Transaction({
920
941
  feePayer: sender.publicKey,
@@ -927,91 +948,6 @@ var StreamClient = /** @class */ (function () {
927
948
  });
928
949
  });
929
950
  };
930
- return StreamClient;
931
- }());
932
- exports.default = StreamClient;
933
- function getProgramAccounts(connection, wallet, offset, programId) {
934
- return __awaiter(this, void 0, void 0, function () {
935
- return __generator(this, function (_a) {
936
- return [2 /*return*/, connection === null || connection === void 0 ? void 0 : connection.getProgramAccounts(programId, {
937
- filters: [
938
- {
939
- memcmp: {
940
- offset: offset,
941
- bytes: wallet.toBase58(),
942
- },
943
- },
944
- ],
945
- })];
946
- });
947
- });
948
- }
949
- function ata(mint, account) {
950
- return __awaiter(this, void 0, void 0, function () {
951
- return __generator(this, function (_a) {
952
- switch (_a.label) {
953
- case 0: return [4 /*yield*/, spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mint, account, true)];
954
- case 1: return [2 /*return*/, _a.sent()];
955
- }
956
- });
957
- });
958
- }
959
- function isAnchorWallet(wallet) {
960
- return wallet.signTransaction !== undefined;
961
- }
962
- function signAllTransactionWithRecipients(sender, batch) {
963
- return __awaiter(this, void 0, void 0, function () {
964
- var signed_batch, isKeypair, isWallet;
965
- return __generator(this, function (_a) {
966
- switch (_a.label) {
967
- case 0:
968
- signed_batch = [];
969
- isKeypair = sender instanceof web3_js_1.Keypair;
970
- isWallet = isAnchorWallet(sender);
971
- if (!isKeypair && !isWallet)
972
- return [2 /*return*/, signed_batch];
973
- if (!isKeypair) return [3 /*break*/, 1];
974
- batch.map(function (t) {
975
- t.tx.partialSign(sender);
976
- return { tx: t.tx, recipient: t.recipient };
977
- });
978
- return [3 /*break*/, 3];
979
- case 1:
980
- if (!isWallet) return [3 /*break*/, 3];
981
- return [4 /*yield*/, sender.signAllTransactions(batch.map(function (t) { return t.tx; }))];
982
- case 2:
983
- _a.sent();
984
- _a.label = 3;
985
- case 3: return [2 /*return*/, batch];
986
- }
987
- });
988
- });
989
- }
990
- function sendAndConfirmStreamRawTransaction(connection, batchItem) {
991
- return __awaiter(this, void 0, void 0, function () {
992
- var rawTx, _a, lastValidBlockHeight, signature, recentBlockhash, confirmationStrategy, completedTxSignature, error_1;
993
- return __generator(this, function (_b) {
994
- switch (_b.label) {
995
- case 0:
996
- _b.trys.push([0, 2, , 3]);
997
- rawTx = batchItem.tx.serialize();
998
- _a = batchItem.tx, lastValidBlockHeight = _a.lastValidBlockHeight, signature = _a.signature, recentBlockhash = _a.recentBlockhash;
999
- if (!lastValidBlockHeight || !signature || !recentBlockhash)
1000
- throw { recipient: batchItem.recipient, error: "no recent blockhash" };
1001
- confirmationStrategy = {
1002
- lastValidBlockHeight: lastValidBlockHeight,
1003
- signature: (0, bs58_1.encode)(signature),
1004
- blockhash: recentBlockhash,
1005
- };
1006
- return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(connection, rawTx, confirmationStrategy)];
1007
- case 1:
1008
- completedTxSignature = _b.sent();
1009
- return [2 /*return*/, __assign(__assign({}, batchItem), { signature: completedTxSignature })];
1010
- case 2:
1011
- error_1 = _b.sent();
1012
- throw { recipient: batchItem.recipient, error: error_1 };
1013
- case 3: return [2 /*return*/];
1014
- }
1015
- });
1016
- });
1017
- }
951
+ return SolanaStreamClient;
952
+ }(StreamClient_1.GenericStreamClient));
953
+ exports.default = SolanaStreamClient;