@streamflow/stream 5.10.3 → 5.11.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.
@@ -64,7 +64,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
64
64
  function verb(n) { return function (v) { return step([n, v]); }; }
65
65
  function step(op) {
66
66
  if (f) throw new TypeError("Generator is already executing.");
67
- while (_) try {
67
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
68
68
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
69
69
  if (y = 0, t) op = [op[0] & 2, t.value];
70
70
  switch (op[0]) {
@@ -129,7 +129,6 @@ var bn_js_1 = __importDefault(require("bn.js"));
129
129
  var buffer_1 = require("buffer");
130
130
  var spl_token_1 = require("@solana/spl-token");
131
131
  var web3_js_1 = require("@solana/web3.js");
132
- var spl_token_2 = require("@solana/spl-token");
133
132
  var borsh = __importStar(require("borsh"));
134
133
  var types_1 = require("./types");
135
134
  var utils_1 = require("./utils");
@@ -138,6 +137,7 @@ var instructions_1 = require("./instructions");
138
137
  var types_2 = require("../common/types");
139
138
  var BaseStreamClient_1 = require("../common/BaseStreamClient");
140
139
  var utils_2 = require("../common/utils");
140
+ var constants_2 = require("../common/constants");
141
141
  var METADATA_ACC_SIZE = 1104;
142
142
  var SolanaStreamClient = /** @class */ (function (_super) {
143
143
  __extends(SolanaStreamClient, _super);
@@ -158,6 +158,9 @@ var SolanaStreamClient = /** @class */ (function (_super) {
158
158
  SolanaStreamClient.prototype.getConnection = function () {
159
159
  return this.connection;
160
160
  };
161
+ SolanaStreamClient.prototype.getCommitment = function () {
162
+ return typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
163
+ };
161
164
  SolanaStreamClient.prototype.getProgramId = function () {
162
165
  return this.programId.toBase58();
163
166
  };
@@ -165,48 +168,73 @@ var SolanaStreamClient = /** @class */ (function (_super) {
165
168
  * Creates a new stream/vesting contract.
166
169
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
167
170
  */
168
- SolanaStreamClient.prototype.create = function (_a, _b) {
171
+ SolanaStreamClient.prototype.create = function (data, extensions) {
172
+ return __awaiter(this, void 0, void 0, function () {
173
+ var _a, ixs, metadata, metadataPubKey, _b, tx, hash, signature;
174
+ return __generator(this, function (_c) {
175
+ switch (_c.label) {
176
+ case 0: return [4 /*yield*/, this.prepareCreateInstructions(data, extensions)];
177
+ case 1:
178
+ _a = _c.sent(), ixs = _a.ixs, metadata = _a.metadata, metadataPubKey = _a.metadataPubKey;
179
+ return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extensions.sender.publicKey, this.getCommitment(), metadata)];
180
+ case 2:
181
+ _b = _c.sent(), tx = _b.tx, hash = _b.hash;
182
+ return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extensions.sender, tx, hash)];
183
+ case 3:
184
+ signature = _c.sent();
185
+ return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
186
+ }
187
+ });
188
+ });
189
+ };
190
+ /**
191
+ * Creates a new stream/vesting contract.
192
+ * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
193
+ */
194
+ SolanaStreamClient.prototype.prepareCreateInstructions = function (_a, _b) {
169
195
  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, partner = _a.partner;
170
- var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
196
+ var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
171
197
  return __awaiter(this, void 0, void 0, function () {
172
- var ixs, mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, _g, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, totalFee, totalAmount, _h, _j, _k, _l, commitment, hash, tx, signature;
173
- var _m;
174
- return __generator(this, function (_o) {
175
- switch (_o.label) {
198
+ var ixs, mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, _g, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, totalFee, totalAmount, _h, _j, _k, _l;
199
+ return __generator(this, function (_m) {
200
+ switch (_m.label) {
176
201
  case 0:
177
202
  if (!sender.publicKey) {
178
203
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
179
204
  }
180
- ixs = [];
205
+ ixs = this.prepareBaseInstructions({
206
+ computePrice: computePrice,
207
+ computeLimit: computeLimit,
208
+ });
181
209
  mintPublicKey = isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(mint);
182
210
  recipientPublicKey = new web3_js_1.PublicKey(recipient);
183
211
  _f = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _f.metadata, metadataPubKey = _f.metadataPubKey;
184
212
  _g = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _g[0];
185
213
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
186
214
  case 1:
187
- senderTokens = _o.sent();
215
+ senderTokens = _m.sent();
188
216
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
189
217
  case 2:
190
- recipientTokens = _o.sent();
218
+ recipientTokens = _m.sent();
191
219
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
192
220
  case 3:
193
- streamflowTreasuryTokens = _o.sent();
221
+ streamflowTreasuryTokens = _m.sent();
194
222
  partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
195
223
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
196
224
  case 4:
197
- partnerTokens = _o.sent();
225
+ partnerTokens = _m.sent();
198
226
  if (!isNative) return [3 /*break*/, 7];
199
227
  return [4 /*yield*/, this.getTotalFee({ address: partner !== null && partner !== void 0 ? partner : sender.publicKey.toBase58() })];
200
228
  case 5:
201
- totalFee = _o.sent();
229
+ totalFee = _m.sent();
202
230
  totalAmount = (0, utils_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
203
231
  _j = (_h = ixs.push).apply;
204
232
  _k = [ixs];
205
233
  _l = [[]];
206
234
  return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)];
207
235
  case 6:
208
- _j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(_o.sent())]), false]))]));
209
- _o.label = 7;
236
+ _j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(_m.sent())]), false]))]));
237
+ _m.label = 7;
210
238
  case 7:
211
239
  ixs.push((0, instructions_1.createStreamInstruction)({
212
240
  start: new bn_js_1.default(start),
@@ -243,22 +271,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
243
271
  withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
244
272
  systemProgram: web3_js_1.SystemProgram.programId,
245
273
  }));
246
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
247
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
248
- case 8:
249
- hash = _o.sent();
250
- tx = (_m = new web3_js_1.Transaction({
251
- feePayer: sender.publicKey,
252
- blockhash: hash.blockhash,
253
- lastValidBlockHeight: hash.lastValidBlockHeight,
254
- })).add.apply(_m, __spreadArray([], __read(ixs), false));
255
- if (metadata) {
256
- tx.partialSign(metadata);
257
- }
258
- return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, sender, tx, hash)];
259
- case 9:
260
- signature = _o.sent();
261
- return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
274
+ return [2 /*return*/, { ixs: ixs, metadata: metadata, metadataPubKey: metadataPubKey }];
262
275
  }
263
276
  });
264
277
  });
@@ -273,14 +286,35 @@ var SolanaStreamClient = /** @class */ (function (_super) {
273
286
  *
274
287
  * If you are not sure if you should use create or create_unchecked, go for create to be safer.
275
288
  */
276
- SolanaStreamClient.prototype.createUnchecked = function (_a, _b) {
289
+ SolanaStreamClient.prototype.createUnchecked = function (data, extensions) {
290
+ return __awaiter(this, void 0, void 0, function () {
291
+ var _a, ixs, metadata, metadataPubKey, _b, tx, hash, signature;
292
+ return __generator(this, function (_c) {
293
+ switch (_c.label) {
294
+ case 0: return [4 /*yield*/, this.prepareCreateUncheckedInstructions(data, extensions)];
295
+ case 1:
296
+ _a = _c.sent(), ixs = _a.ixs, metadata = _a.metadata, metadataPubKey = _a.metadataPubKey;
297
+ return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extensions.sender.publicKey, this.getCommitment(), metadata)];
298
+ case 2:
299
+ _b = _c.sent(), tx = _b.tx, hash = _b.hash;
300
+ return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extensions.sender, tx, hash)];
301
+ case 3:
302
+ signature = _c.sent();
303
+ return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
304
+ }
305
+ });
306
+ });
307
+ };
308
+ /**
309
+ * Create Transaction instructions for `createUnchecked`
310
+ */
311
+ SolanaStreamClient.prototype.prepareCreateUncheckedInstructions = function (_a, _b) {
277
312
  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, partner = _a.partner;
278
- var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
313
+ var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
279
314
  return __awaiter(this, void 0, void 0, function () {
280
- var mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, rentToExempt, createMetadataInstruction, _g, escrowTokens, senderTokens, partnerPublicKey, nativeInstructions, _h, createInstruction, commitment, ixs, hash, tx, signature;
281
- var _j;
282
- return __generator(this, function (_k) {
283
- switch (_k.label) {
315
+ var mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, rentToExempt, createMetadataInstruction, _g, escrowTokens, senderTokens, partnerPublicKey, ixs, totalFee, totalAmount, _h, _j, _k, _l, createInstruction;
316
+ return __generator(this, function (_m) {
317
+ switch (_m.label) {
284
318
  case 0:
285
319
  if (!sender.publicKey) {
286
320
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
@@ -290,7 +324,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
290
324
  _f = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _f.metadata, metadataPubKey = _f.metadataPubKey;
291
325
  return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
292
326
  case 1:
293
- rentToExempt = _k.sent();
327
+ rentToExempt = _m.sent();
294
328
  createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
295
329
  programId: this.programId,
296
330
  space: METADATA_ACC_SIZE,
@@ -301,18 +335,25 @@ var SolanaStreamClient = /** @class */ (function (_super) {
301
335
  _g = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _g[0];
302
336
  return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
303
337
  case 2:
304
- senderTokens = _k.sent();
338
+ senderTokens = _m.sent();
305
339
  partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
306
- if (!isNative) return [3 /*break*/, 4];
307
- return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
340
+ ixs = this.prepareBaseInstructions({
341
+ computePrice: computePrice,
342
+ computeLimit: computeLimit,
343
+ });
344
+ if (!isNative) return [3 /*break*/, 5];
345
+ return [4 /*yield*/, this.getTotalFee({ address: partner !== null && partner !== void 0 ? partner : sender.publicKey.toBase58() })];
308
346
  case 3:
309
- _h = _k.sent();
310
- return [3 /*break*/, 5];
347
+ totalFee = _m.sent();
348
+ totalAmount = (0, utils_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
349
+ _j = (_h = ixs.push).apply;
350
+ _k = [ixs];
351
+ _l = [[]];
352
+ return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)];
311
353
  case 4:
312
- _h = [];
313
- _k.label = 5;
354
+ _j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(_m.sent())]), false]))]));
355
+ _m.label = 5;
314
356
  case 5:
315
- nativeInstructions = _h;
316
357
  createInstruction = (0, instructions_1.createUncheckedStreamInstruction)({
317
358
  start: new bn_js_1.default(start),
318
359
  depositedAmount: depositedAmount,
@@ -343,23 +384,8 @@ var SolanaStreamClient = /** @class */ (function (_super) {
343
384
  withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
344
385
  systemProgram: web3_js_1.SystemProgram.programId,
345
386
  });
346
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
347
- ixs = [createMetadataInstruction, createInstruction];
348
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
349
- case 6:
350
- hash = _k.sent();
351
- tx = (_j = new web3_js_1.Transaction({
352
- feePayer: sender.publicKey,
353
- blockhash: hash.blockhash,
354
- lastValidBlockHeight: hash.lastValidBlockHeight,
355
- })).add.apply(_j, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
356
- if (metadata) {
357
- tx.partialSign(metadata);
358
- }
359
- return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, sender, tx, hash)];
360
- case 7:
361
- signature = _k.sent();
362
- return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
387
+ ixs.push(createMetadataInstruction, createInstruction);
388
+ return [2 /*return*/, { ixs: ixs, metadata: metadata, metadataPubKey: metadataPubKey }];
363
389
  }
364
390
  });
365
391
  });
@@ -371,7 +397,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
371
397
  SolanaStreamClient.prototype.createMultiple = function (data, _a) {
372
398
  var sender = _a.sender, metadataPubKeys = _a.metadataPubKeys, _b = _a.isNative, isNative = _b === void 0 ? false : _b;
373
399
  return __awaiter(this, void 0, void 0, function () {
374
- var recipients, metadatas, metadataToRecipient, errors, signatures, batch, instructionsBatch, i, recipientData, _c, ixs, metadata, metadataPubKey, commitment, hash, instructionsBatch_1, instructionsBatch_1_1, _d, ixs, metadata, recipient, tx, totalDepositedAmount, nativeInstructions, prepareTransaction, signedBatch, prepareTx, responses, signedBatch_1, signedBatch_1_1, batchTx, _e, _f, _g, _h, e_1_1, batchTransactionsCalls, _j, _k, _l, _m, successes, failures;
400
+ var recipients, metadatas, metadataToRecipient, errors, signatures, batch, instructionsBatch, i, recipientData, _c, ixs, metadata, metadataPubKey, commitment, hash, instructionsBatch_1, instructionsBatch_1_1, _d, ixs, metadata, recipient, tx, totalDepositedAmount, nativeInstructions, prepareTransaction_1, signedBatch, prepareTx, responses, signedBatch_1, signedBatch_1_1, batchTx, _e, _f, _g, _h, e_1_1, batchTransactionsCalls, _j, _k, _l, _m, successes, failures;
375
401
  var e_2, _o, _p, _q, e_1, _r;
376
402
  var _this = this;
377
403
  return __generator(this, function (_s) {
@@ -437,12 +463,12 @@ var SolanaStreamClient = /** @class */ (function (_super) {
437
463
  return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
438
464
  case 6:
439
465
  nativeInstructions = _s.sent();
440
- prepareTransaction = (_q = new web3_js_1.Transaction({
466
+ prepareTransaction_1 = (_q = new web3_js_1.Transaction({
441
467
  feePayer: sender.publicKey,
442
468
  blockhash: hash.blockhash,
443
469
  lastValidBlockHeight: hash.lastValidBlockHeight,
444
470
  })).add.apply(_q, __spreadArray([], __read(nativeInstructions), false));
445
- batch.push({ tx: prepareTransaction, recipient: sender.publicKey.toBase58() });
471
+ batch.push({ tx: prepareTransaction_1, recipient: sender.publicKey.toBase58() });
446
472
  _s.label = 7;
447
473
  case 7: return [4 /*yield*/, (0, utils_1.signAllTransactionWithRecipients)(sender, batch)];
448
474
  case 8:
@@ -520,18 +546,44 @@ var SolanaStreamClient = /** @class */ (function (_super) {
520
546
  * Attempts withdrawing from the specified stream.
521
547
  */
522
548
  SolanaStreamClient.prototype.withdraw = function (_a, _b) {
523
- var id = _a.id, amount = _a.amount;
549
+ var id = _a.id, _c = _a.amount, amount = _c === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _c;
524
550
  var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts;
525
551
  return __awaiter(this, void 0, void 0, function () {
526
- var ixs, streamPublicKey, escrow, data, streamflowTreasuryTokens, partnerTokens, commitment, hash, tx, signature;
527
- var _c;
552
+ var ixs, _d, tx, hash, signature;
553
+ return __generator(this, function (_e) {
554
+ switch (_e.label) {
555
+ case 0: return [4 /*yield*/, this.prepareWithdawInstructions({ id: id, amount: amount }, { invoker: invoker, checkTokenAccounts: checkTokenAccounts })];
556
+ case 1:
557
+ ixs = _e.sent();
558
+ return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, invoker.publicKey, this.getCommitment())];
559
+ case 2:
560
+ _d = _e.sent(), tx = _d.tx, hash = _d.hash;
561
+ return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
562
+ case 3:
563
+ signature = _e.sent();
564
+ return [2 /*return*/, { ixs: ixs, txId: signature }];
565
+ }
566
+ });
567
+ });
568
+ };
569
+ /**
570
+ * Creates Transaction Instructions for withdrawal
571
+ */
572
+ SolanaStreamClient.prototype.prepareWithdawInstructions = function (_a, _b) {
573
+ var id = _a.id, _c = _a.amount, amount = _c === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _c;
574
+ var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
575
+ return __awaiter(this, void 0, void 0, function () {
576
+ var ixs, streamPublicKey, escrow, data, streamflowTreasuryTokens, partnerTokens;
528
577
  return __generator(this, function (_d) {
529
578
  switch (_d.label) {
530
579
  case 0:
531
580
  if (!invoker.publicKey) {
532
581
  throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
533
582
  }
534
- ixs = [];
583
+ ixs = this.prepareBaseInstructions({
584
+ computePrice: computePrice,
585
+ computeLimit: computeLimit,
586
+ });
535
587
  streamPublicKey = new web3_js_1.PublicKey(id);
536
588
  return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
537
589
  case 1:
@@ -562,19 +614,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
562
614
  mint: data.mint,
563
615
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
564
616
  }));
565
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
566
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
567
- case 5:
568
- hash = _d.sent();
569
- tx = (_c = new web3_js_1.Transaction({
570
- feePayer: invoker.publicKey,
571
- blockhash: hash.blockhash,
572
- lastValidBlockHeight: hash.lastValidBlockHeight,
573
- })).add.apply(_c, __spreadArray([], __read(ixs), false));
574
- return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
575
- case 6:
576
- signature = _d.sent();
577
- return [2 /*return*/, { ixs: ixs, txId: signature }];
617
+ return [2 /*return*/, ixs];
578
618
  }
579
619
  });
580
620
  });
@@ -582,14 +622,36 @@ var SolanaStreamClient = /** @class */ (function (_super) {
582
622
  /**
583
623
  * Attempts canceling the specified stream.
584
624
  */
585
- SolanaStreamClient.prototype.cancel = function (_a, _b) {
625
+ SolanaStreamClient.prototype.cancel = function (_a, extensions) {
586
626
  var id = _a.id;
587
- var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts;
588
627
  return __awaiter(this, void 0, void 0, function () {
589
- var streamPublicKey, escrowAcc, data, streamflowTreasuryTokens, partnerTokens, ixs, commitment, hash, tx, signature;
590
- var _c;
591
- return __generator(this, function (_d) {
592
- switch (_d.label) {
628
+ var ixs, _b, tx, hash, signature;
629
+ return __generator(this, function (_c) {
630
+ switch (_c.label) {
631
+ case 0: return [4 /*yield*/, this.prepareCancelInstructions({ id: id }, extensions)];
632
+ case 1:
633
+ ixs = _c.sent();
634
+ return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extensions.invoker.publicKey, this.getCommitment())];
635
+ case 2:
636
+ _b = _c.sent(), tx = _b.tx, hash = _b.hash;
637
+ return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extensions.invoker, tx, hash)];
638
+ case 3:
639
+ signature = _c.sent();
640
+ return [2 /*return*/, { ixs: ixs, txId: signature }];
641
+ }
642
+ });
643
+ });
644
+ };
645
+ /**
646
+ * Creates Transaction Instructions for cancel
647
+ */
648
+ SolanaStreamClient.prototype.prepareCancelInstructions = function (_a, _b) {
649
+ var id = _a.id;
650
+ var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
651
+ return __awaiter(this, void 0, void 0, function () {
652
+ var streamPublicKey, escrowAcc, data, streamflowTreasuryTokens, partnerTokens, ixs;
653
+ return __generator(this, function (_c) {
654
+ switch (_c.label) {
593
655
  case 0:
594
656
  if (!invoker.publicKey) {
595
657
  throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
@@ -597,21 +659,24 @@ var SolanaStreamClient = /** @class */ (function (_super) {
597
659
  streamPublicKey = new web3_js_1.PublicKey(id);
598
660
  return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
599
661
  case 1:
600
- escrowAcc = _d.sent();
662
+ escrowAcc = _c.sent();
601
663
  if (!(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data)) {
602
664
  throw new Error("Couldn't get account info");
603
665
  }
604
666
  data = (0, utils_1.decodeStream)(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data);
605
667
  return [4 /*yield*/, (0, utils_1.ata)(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
606
668
  case 2:
607
- streamflowTreasuryTokens = _d.sent();
669
+ streamflowTreasuryTokens = _c.sent();
608
670
  return [4 /*yield*/, (0, utils_1.ata)(data.mint, data.partner)];
609
671
  case 3:
610
- partnerTokens = _d.sent();
611
- ixs = [];
672
+ partnerTokens = _c.sent();
673
+ ixs = this.prepareBaseInstructions({
674
+ computePrice: computePrice,
675
+ computeLimit: computeLimit,
676
+ });
612
677
  return [4 /*yield*/, this.checkAssociatedTokenAccounts(data, { invoker: invoker, checkTokenAccounts: checkTokenAccounts }, ixs)];
613
678
  case 4:
614
- _d.sent();
679
+ _c.sent();
615
680
  ixs.push((0, instructions_1.cancelStreamInstruction)(this.programId, {
616
681
  authority: invoker.publicKey,
617
682
  sender: data.sender,
@@ -627,18 +692,30 @@ var SolanaStreamClient = /** @class */ (function (_super) {
627
692
  mint: data.mint,
628
693
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
629
694
  }));
630
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
631
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
632
- case 5:
633
- hash = _d.sent();
634
- tx = (_c = new web3_js_1.Transaction({
635
- feePayer: invoker.publicKey,
636
- blockhash: hash.blockhash,
637
- lastValidBlockHeight: hash.lastValidBlockHeight,
638
- })).add.apply(_c, __spreadArray([], __read(ixs), false));
639
- return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
640
- case 6:
641
- signature = _d.sent();
695
+ return [2 /*return*/, ixs];
696
+ }
697
+ });
698
+ });
699
+ };
700
+ /**
701
+ * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
702
+ * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
703
+ */
704
+ SolanaStreamClient.prototype.transfer = function (_a, extensions) {
705
+ var id = _a.id, newRecipient = _a.newRecipient;
706
+ return __awaiter(this, void 0, void 0, function () {
707
+ var ixs, _b, tx, hash, signature;
708
+ return __generator(this, function (_c) {
709
+ switch (_c.label) {
710
+ case 0: return [4 /*yield*/, this.prepareTransferInstructions({ id: id, newRecipient: newRecipient }, extensions)];
711
+ case 1:
712
+ ixs = _c.sent();
713
+ return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extensions.invoker.publicKey, this.getCommitment())];
714
+ case 2:
715
+ _b = _c.sent(), tx = _b.tx, hash = _b.hash;
716
+ return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extensions.invoker, tx, hash)];
717
+ case 3:
718
+ signature = _c.sent();
642
719
  return [2 /*return*/, { ixs: ixs, txId: signature }];
643
720
  }
644
721
  });
@@ -648,21 +725,23 @@ var SolanaStreamClient = /** @class */ (function (_super) {
648
725
  * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
649
726
  * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
650
727
  */
651
- SolanaStreamClient.prototype.transfer = function (_a, _b) {
652
- var id = _a.id, newRecipientString = _a.newRecipient;
653
- var invoker = _b.invoker;
728
+ SolanaStreamClient.prototype.prepareTransferInstructions = function (_a, _b) {
729
+ var id = _a.id, newRecipient = _a.newRecipient;
730
+ var invoker = _b.invoker, computePrice = _b.computePrice, _c = _b.computeLimit, computeLimit = _c === void 0 ? 100001 : _c;
654
731
  return __awaiter(this, void 0, void 0, function () {
655
- var ixs, stream, newRecipient, escrow, mint, newRecipientTokens, commitment, hash, tx, signature;
656
- var _c;
732
+ var ixs, stream, newRecipientPublicKey, escrow, mint, newRecipientTokens;
657
733
  return __generator(this, function (_d) {
658
734
  switch (_d.label) {
659
735
  case 0:
660
736
  if (!invoker.publicKey) {
661
737
  throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
662
738
  }
663
- ixs = [];
739
+ ixs = this.prepareBaseInstructions({
740
+ computePrice: computePrice,
741
+ computeLimit: computeLimit,
742
+ });
664
743
  stream = new web3_js_1.PublicKey(id);
665
- newRecipient = new web3_js_1.PublicKey(newRecipientString);
744
+ newRecipientPublicKey = new web3_js_1.PublicKey(newRecipient);
666
745
  return [4 /*yield*/, this.connection.getAccountInfo(stream)];
667
746
  case 1:
668
747
  escrow = _d.sent();
@@ -670,13 +749,12 @@ var SolanaStreamClient = /** @class */ (function (_super) {
670
749
  throw new Error("Couldn't get account info");
671
750
  }
672
751
  mint = (0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data).mint;
673
- return [4 /*yield*/, (0, utils_1.ata)(mint, newRecipient)];
752
+ return [4 /*yield*/, (0, utils_1.ata)(mint, newRecipientPublicKey)];
674
753
  case 2:
675
754
  newRecipientTokens = _d.sent();
676
- ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 100001 }));
677
755
  ixs.push((0, instructions_1.transferStreamInstruction)(this.programId, {
678
756
  authority: invoker.publicKey,
679
- newRecipient: newRecipient,
757
+ newRecipient: newRecipientPublicKey,
680
758
  newRecipientTokens: newRecipientTokens,
681
759
  metadata: stream,
682
760
  mint: mint,
@@ -685,63 +763,75 @@ var SolanaStreamClient = /** @class */ (function (_super) {
685
763
  associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
686
764
  systemProgram: web3_js_1.SystemProgram.programId,
687
765
  }));
688
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
689
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
766
+ return [2 /*return*/, ixs];
767
+ }
768
+ });
769
+ });
770
+ };
771
+ /**
772
+ * Tops up stream account with specified amount.
773
+ */
774
+ SolanaStreamClient.prototype.topup = function (_a, extensions) {
775
+ var id = _a.id, amount = _a.amount;
776
+ return __awaiter(this, void 0, void 0, function () {
777
+ var ixs, _b, tx, hash, signature;
778
+ return __generator(this, function (_c) {
779
+ switch (_c.label) {
780
+ case 0: return [4 /*yield*/, this.prepareTopupInstructions({ id: id, amount: amount }, extensions)];
781
+ case 1:
782
+ ixs = _c.sent();
783
+ return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extensions.invoker.publicKey, this.getCommitment())];
784
+ case 2:
785
+ _b = _c.sent(), tx = _b.tx, hash = _b.hash;
786
+ return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extensions.invoker, tx, hash)];
690
787
  case 3:
691
- hash = _d.sent();
692
- tx = (_c = new web3_js_1.Transaction({
693
- feePayer: invoker.publicKey,
694
- blockhash: hash.blockhash,
695
- lastValidBlockHeight: hash.lastValidBlockHeight,
696
- })).add.apply(_c, __spreadArray([], __read(ixs), false));
697
- return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
698
- case 4:
699
- signature = _d.sent();
788
+ signature = _c.sent();
700
789
  return [2 /*return*/, { ixs: ixs, txId: signature }];
701
790
  }
702
791
  });
703
792
  });
704
793
  };
705
794
  /**
706
- * Tops up stream account with specified amount.
795
+ * Create Transaction instructions for topup
707
796
  */
708
- SolanaStreamClient.prototype.topup = function (_a, _b) {
797
+ SolanaStreamClient.prototype.prepareTopupInstructions = function (_a, _b) {
709
798
  var id = _a.id, amount = _a.amount;
710
- var invoker = _b.invoker, isNative = _b.isNative;
799
+ var invoker = _b.invoker, isNative = _b.isNative, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
711
800
  return __awaiter(this, void 0, void 0, function () {
712
- var ixs, streamPublicKey, escrow, _c, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, nativeInstructions, _d, commitment, hash, tx, signature;
713
- var _e;
714
- return __generator(this, function (_f) {
715
- switch (_f.label) {
801
+ var ixs, streamPublicKey, escrow, _c, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, _d, _e, _f, _g;
802
+ return __generator(this, function (_h) {
803
+ switch (_h.label) {
716
804
  case 0:
717
805
  if (!invoker.publicKey) {
718
806
  throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
719
807
  }
720
- ixs = [];
808
+ ixs = this.prepareBaseInstructions({
809
+ computePrice: computePrice,
810
+ computeLimit: computeLimit,
811
+ });
721
812
  streamPublicKey = new web3_js_1.PublicKey(id);
722
813
  return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
723
814
  case 1:
724
- escrow = _f.sent();
815
+ escrow = _h.sent();
725
816
  if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
726
817
  throw new Error("Couldn't get account info");
727
818
  }
728
819
  _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;
729
820
  return [4 /*yield*/, (0, utils_1.ata)(mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
730
821
  case 2:
731
- streamflowTreasuryTokens = _f.sent();
822
+ streamflowTreasuryTokens = _h.sent();
732
823
  return [4 /*yield*/, (0, utils_1.ata)(mint, partner)];
733
824
  case 3:
734
- partnerTokens = _f.sent();
825
+ partnerTokens = _h.sent();
735
826
  if (!isNative) return [3 /*break*/, 5];
827
+ _e = (_d = ixs.push).apply;
828
+ _f = [ixs];
829
+ _g = [[]];
736
830
  return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, invoker.publicKey, amount)];
737
831
  case 4:
738
- _d = _f.sent();
739
- return [3 /*break*/, 6];
832
+ _e.apply(_d, _f.concat([__spreadArray.apply(void 0, _g.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
833
+ _h.label = 5;
740
834
  case 5:
741
- _d = [];
742
- _f.label = 6;
743
- case 6:
744
- nativeInstructions = _d;
745
835
  ixs.push((0, instructions_1.topupStreamInstruction)(amount, this.programId, {
746
836
  sender: invoker.publicKey,
747
837
  senderTokens: senderTokens,
@@ -756,19 +846,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
756
846
  withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
757
847
  systemProgram: web3_js_1.SystemProgram.programId,
758
848
  }));
759
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
760
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
761
- case 7:
762
- hash = _f.sent();
763
- tx = (_e = new web3_js_1.Transaction({
764
- feePayer: invoker.publicKey,
765
- blockhash: hash.blockhash,
766
- lastValidBlockHeight: hash.lastValidBlockHeight,
767
- })).add.apply(_e, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
768
- return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
769
- case 8:
770
- signature = _f.sent();
771
- return [2 /*return*/, { ixs: ixs, txId: signature }];
849
+ return [2 /*return*/, ixs];
772
850
  }
773
851
  });
774
852
  });
@@ -843,10 +921,35 @@ var SolanaStreamClient = /** @class */ (function (_super) {
843
921
  /**
844
922
  * Attempts updating the stream auto withdrawal params and amount per period
845
923
  */
846
- SolanaStreamClient.prototype.update = function (data, _a) {
847
- var invoker = _a.invoker;
924
+ SolanaStreamClient.prototype.update = function (data, extensions) {
925
+ return __awaiter(this, void 0, void 0, function () {
926
+ var ixs, _a, tx, hash, signature;
927
+ return __generator(this, function (_b) {
928
+ switch (_b.label) {
929
+ case 0: return [4 /*yield*/, this.prepareUpdateInstructions(data, extensions)];
930
+ case 1:
931
+ ixs = _b.sent();
932
+ return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extensions.invoker.publicKey, this.getCommitment())];
933
+ case 2:
934
+ _a = _b.sent(), tx = _a.tx, hash = _a.hash;
935
+ return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extensions.invoker, tx, hash)];
936
+ case 3:
937
+ signature = _b.sent();
938
+ return [2 /*return*/, {
939
+ ixs: ixs,
940
+ txId: signature,
941
+ }];
942
+ }
943
+ });
944
+ });
945
+ };
946
+ /**
947
+ * Create Transaction instructions for update
948
+ */
949
+ SolanaStreamClient.prototype.prepareUpdateInstructions = function (data, _a) {
950
+ var invoker = _a.invoker, computePrice = _a.computePrice, computeLimit = _a.computeLimit;
848
951
  return __awaiter(this, void 0, void 0, function () {
849
- var streamPublicKey, escrow, updateIx, commitment, hash, tx, signature;
952
+ var streamPublicKey, escrow, ixs;
850
953
  return __generator(this, function (_b) {
851
954
  switch (_b.label) {
852
955
  case 0:
@@ -860,28 +963,17 @@ var SolanaStreamClient = /** @class */ (function (_super) {
860
963
  if (!escrow) {
861
964
  throw new Error("Couldn't get account info");
862
965
  }
863
- updateIx = (0, instructions_1.updateStreamInstruction)(data, this.programId, {
966
+ ixs = this.prepareBaseInstructions({
967
+ computePrice: computePrice,
968
+ computeLimit: computeLimit,
969
+ });
970
+ ixs.push((0, instructions_1.updateStreamInstruction)(data, this.programId, {
864
971
  authority: invoker.publicKey,
865
972
  metadata: streamPublicKey,
866
973
  withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
867
974
  systemProgram: web3_js_1.SystemProgram.programId,
868
- });
869
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
870
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
871
- case 2:
872
- hash = _b.sent();
873
- tx = new web3_js_1.Transaction({
874
- feePayer: invoker.publicKey,
875
- blockhash: hash.blockhash,
876
- lastValidBlockHeight: hash.lastValidBlockHeight,
877
- }).add(updateIx);
878
- return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
879
- case 3:
880
- signature = _b.sent();
881
- return [2 /*return*/, {
882
- ixs: [updateIx],
883
- txId: signature,
884
- }];
975
+ }));
976
+ return [2 /*return*/, ixs];
885
977
  }
886
978
  });
887
979
  });
@@ -996,6 +1088,37 @@ var SolanaStreamClient = /** @class */ (function (_super) {
996
1088
  });
997
1089
  });
998
1090
  };
1091
+ /**
1092
+ * Create Base instructions for Solana
1093
+ * - sets compute price if `computePrice` is provided
1094
+ * - sets compute limit if `computeLimit` is provided
1095
+ */
1096
+ SolanaStreamClient.prototype.prepareBaseInstructions = function (_a) {
1097
+ var computePrice = _a.computePrice, computeLimit = _a.computeLimit;
1098
+ var ixs = [];
1099
+ if (computePrice) {
1100
+ ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: computePrice }));
1101
+ }
1102
+ if (computeLimit) {
1103
+ ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: computeLimit }));
1104
+ }
1105
+ return ixs;
1106
+ };
1107
+ /**
1108
+ * Utility function to generate metadata for a Contract or return existing Pubkey
1109
+ */
1110
+ SolanaStreamClient.prototype.getOrCreateStreamMetadata = function (metadataPubKeys) {
1111
+ var metadata;
1112
+ var metadataPubKey;
1113
+ if (!metadataPubKeys) {
1114
+ metadata = web3_js_1.Keypair.generate();
1115
+ metadataPubKey = metadata.publicKey;
1116
+ }
1117
+ else {
1118
+ metadataPubKey = metadataPubKeys[0];
1119
+ }
1120
+ return { metadata: metadata, metadataPubKey: metadataPubKey };
1121
+ };
999
1122
  /**
1000
1123
  * Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
1001
1124
  */
@@ -1027,7 +1150,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
1027
1150
  response = _b.sent();
1028
1151
  for (i = 0; i < response.length; i++) {
1029
1152
  if (!response[i]) {
1030
- ixs.push((0, spl_token_2.createAssociatedTokenAccountInstruction)(invoker.publicKey, accountArrays[i][1], accountArrays[i][0], data.mint));
1153
+ ixs.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(invoker.publicKey, accountArrays[i][1], accountArrays[i][0], data.mint));
1031
1154
  }
1032
1155
  }
1033
1156
  return [2 /*return*/];
@@ -1035,21 +1158,6 @@ var SolanaStreamClient = /** @class */ (function (_super) {
1035
1158
  });
1036
1159
  });
1037
1160
  };
1038
- /**
1039
- * Utility function to generate metadata for a Contract or return existing Pubkey
1040
- */
1041
- SolanaStreamClient.prototype.getOrCreateStreamMetadata = function (metadataPubKeys) {
1042
- var metadata;
1043
- var metadataPubKey;
1044
- if (!metadataPubKeys) {
1045
- metadata = web3_js_1.Keypair.generate();
1046
- metadataPubKey = metadata.publicKey;
1047
- }
1048
- else {
1049
- metadataPubKey = metadataPubKeys[0];
1050
- }
1051
- return { metadata: metadata, metadataPubKey: metadataPubKey };
1052
- };
1053
1161
  return SolanaStreamClient;
1054
1162
  }(BaseStreamClient_1.BaseStreamClient));
1055
1163
  exports.default = SolanaStreamClient;