@streamflow/stream 5.6.0 → 5.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/LICENSE +674 -0
  2. package/package.json +5 -6
  3. package/dist/__tests__/aptos/streamClient.spec.d.ts +0 -1
  4. package/dist/__tests__/aptos/streamClient.spec.js +0 -161
  5. package/dist/aptos/StreamClient.d.ts +0 -51
  6. package/dist/aptos/StreamClient.js +0 -387
  7. package/dist/aptos/constants.d.ts +0 -8
  8. package/dist/aptos/constants.js +0 -28
  9. package/dist/aptos/index.d.ts +0 -2
  10. package/dist/aptos/index.js +0 -24
  11. package/dist/aptos/types.d.ts +0 -97
  12. package/dist/aptos/types.js +0 -76
  13. package/dist/aptos/utils.d.ts +0 -1
  14. package/dist/aptos/utils.js +0 -12
  15. package/dist/aptos/wallet.d.ts +0 -9
  16. package/dist/aptos/wallet.js +0 -89
  17. package/dist/common/BaseStreamClient.d.ts +0 -13
  18. package/dist/common/BaseStreamClient.js +0 -13
  19. package/dist/common/GenericStreamClient.d.ts +0 -93
  20. package/dist/common/GenericStreamClient.js +0 -114
  21. package/dist/common/constants.d.ts +0 -1
  22. package/dist/common/constants.js +0 -4
  23. package/dist/common/contractUtils.d.ts +0 -47
  24. package/dist/common/contractUtils.js +0 -55
  25. package/dist/common/types.d.ts +0 -252
  26. package/dist/common/types.js +0 -165
  27. package/dist/common/utils.d.ts +0 -22
  28. package/dist/common/utils.js +0 -101
  29. package/dist/evm/StreamClient.d.ts +0 -30
  30. package/dist/evm/StreamClient.js +0 -461
  31. package/dist/evm/abi.d.ts +0 -111
  32. package/dist/evm/abi.js +0 -1257
  33. package/dist/evm/constants.d.ts +0 -20
  34. package/dist/evm/constants.js +0 -39
  35. package/dist/evm/ercAbi.d.ts +0 -39
  36. package/dist/evm/ercAbi.js +0 -224
  37. package/dist/evm/index.d.ts +0 -2
  38. package/dist/evm/index.js +0 -24
  39. package/dist/evm/types.d.ts +0 -93
  40. package/dist/evm/types.js +0 -75
  41. package/dist/evm/utils.d.ts +0 -1
  42. package/dist/evm/utils.js +0 -12
  43. package/dist/index.d.ts +0 -8
  44. package/dist/index.js +0 -41
  45. package/dist/solana/StreamClient.d.ts +0 -72
  46. package/dist/solana/StreamClient.js +0 -927
  47. package/dist/solana/constants.d.ts +0 -22
  48. package/dist/solana/constants.js +0 -50
  49. package/dist/solana/index.d.ts +0 -7
  50. package/dist/solana/index.js +0 -43
  51. package/dist/solana/instructionTypes.d.ts +0 -96
  52. package/dist/solana/instructionTypes.js +0 -2
  53. package/dist/solana/instructions.d.ts +0 -139
  54. package/dist/solana/instructions.js +0 -407
  55. package/dist/solana/layout.d.ts +0 -27
  56. package/dist/solana/layout.js +0 -170
  57. package/dist/solana/timelockIDL.d.ts +0 -22
  58. package/dist/solana/timelockIDL.js +0 -422
  59. package/dist/solana/types.d.ts +0 -292
  60. package/dist/solana/types.js +0 -81
  61. package/dist/solana/utils.d.ts +0 -44
  62. package/dist/solana/utils.js +0 -303
  63. package/dist/sui/StreamClient.d.ts +0 -79
  64. package/dist/sui/StreamClient.js +0 -571
  65. package/dist/sui/constants.d.ts +0 -10
  66. package/dist/sui/constants.js +0 -43
  67. package/dist/sui/index.d.ts +0 -2
  68. package/dist/sui/index.js +0 -23
  69. package/dist/sui/types.d.ts +0 -141
  70. package/dist/sui/types.js +0 -102
  71. package/dist/sui/utils.d.ts +0 -2
  72. package/dist/sui/utils.js +0 -29
  73. package/dist/sui/wallet.d.ts +0 -11
  74. package/dist/sui/wallet.js +0 -75
@@ -1,927 +0,0 @@
1
- "use strict";
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
- })();
18
- var __assign = (this && this.__assign) || function () {
19
- __assign = Object.assign || function(t) {
20
- for (var s, i = 1, n = arguments.length; i < n; i++) {
21
- s = arguments[i];
22
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
23
- t[p] = s[p];
24
- }
25
- return t;
26
- };
27
- return __assign.apply(this, arguments);
28
- };
29
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
30
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
31
- return new (P || (P = Promise))(function (resolve, reject) {
32
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
33
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
34
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
35
- step((generator = generator.apply(thisArg, _arguments || [])).next());
36
- });
37
- };
38
- var __generator = (this && this.__generator) || function (thisArg, body) {
39
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
40
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
41
- function verb(n) { return function (v) { return step([n, v]); }; }
42
- function step(op) {
43
- if (f) throw new TypeError("Generator is already executing.");
44
- while (_) try {
45
- 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;
46
- if (y = 0, t) op = [op[0] & 2, t.value];
47
- switch (op[0]) {
48
- case 0: case 1: t = op; break;
49
- case 4: _.label++; return { value: op[1], done: false };
50
- case 5: _.label++; y = op[1]; op = [0]; continue;
51
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
52
- default:
53
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
54
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
55
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
56
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
57
- if (t[2]) _.ops.pop();
58
- _.trys.pop(); continue;
59
- }
60
- op = body.call(thisArg, _);
61
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
62
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
63
- }
64
- };
65
- var __read = (this && this.__read) || function (o, n) {
66
- var m = typeof Symbol === "function" && o[Symbol.iterator];
67
- if (!m) return o;
68
- var i = m.call(o), r, ar = [], e;
69
- try {
70
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
71
- }
72
- catch (error) { e = { error: error }; }
73
- finally {
74
- try {
75
- if (r && !r.done && (m = i["return"])) m.call(i);
76
- }
77
- finally { if (e) throw e.error; }
78
- }
79
- return ar;
80
- };
81
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
82
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
83
- if (ar || !(i in from)) {
84
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
85
- ar[i] = from[i];
86
- }
87
- }
88
- return to.concat(ar || Array.prototype.slice.call(from));
89
- };
90
- var __values = (this && this.__values) || function(o) {
91
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
92
- if (m) return m.call(o);
93
- if (o && typeof o.length === "number") return {
94
- next: function () {
95
- if (o && i >= o.length) o = void 0;
96
- return { value: o && o[i++], done: !o };
97
- }
98
- };
99
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
100
- };
101
- var __importDefault = (this && this.__importDefault) || function (mod) {
102
- return (mod && mod.__esModule) ? mod : { "default": mod };
103
- };
104
- Object.defineProperty(exports, "__esModule", { value: true });
105
- var bn_js_1 = __importDefault(require("bn.js"));
106
- var buffer_1 = require("buffer");
107
- var bs58_1 = __importDefault(require("bs58"));
108
- var spl_token_1 = require("@solana/spl-token");
109
- var web3_js_1 = require("@solana/web3.js");
110
- var types_1 = require("./types");
111
- var utils_1 = require("./utils");
112
- var constants_1 = require("./constants");
113
- var instructions_1 = require("./instructions");
114
- var types_2 = require("../common/types");
115
- var BaseStreamClient_1 = require("../common/BaseStreamClient");
116
- var METADATA_ACC_SIZE = 1104;
117
- var SolanaStreamClient = /** @class */ (function (_super) {
118
- __extends(SolanaStreamClient, _super);
119
- /**
120
- * Create Stream instance
121
- */
122
- function SolanaStreamClient(clusterUrl, cluster, commitment, programId) {
123
- if (cluster === void 0) { cluster = types_2.ICluster.Mainnet; }
124
- if (commitment === void 0) { commitment = "confirmed"; }
125
- if (programId === void 0) { programId = ""; }
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;
132
- }
133
- SolanaStreamClient.prototype.getConnection = function () {
134
- return this.connection;
135
- };
136
- SolanaStreamClient.prototype.getProgramId = function () {
137
- return this.programId.toBase58();
138
- };
139
- /**
140
- * Creates a new stream/vesting contract.
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).
142
- */
143
- SolanaStreamClient.prototype.create = function (_a, _b) {
144
- 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;
145
- var sender = _b.sender, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
146
- return __awaiter(this, void 0, void 0, function () {
147
- var ixs, mintPublicKey, recipientPublicKey, metadata, _f, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, nativeInstructions, _g, commitment, hash, tx, signature;
148
- var _h;
149
- return __generator(this, function (_j) {
150
- switch (_j.label) {
151
- case 0:
152
- if (!sender.publicKey) {
153
- throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
154
- }
155
- ixs = [];
156
- mintPublicKey = isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(mint);
157
- recipientPublicKey = new web3_js_1.PublicKey(recipient);
158
- metadata = web3_js_1.Keypair.generate();
159
- return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
160
- case 1:
161
- _f = __read.apply(void 0, [_j.sent(), 1]), escrowTokens = _f[0];
162
- return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
163
- case 2:
164
- senderTokens = _j.sent();
165
- return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
166
- case 3:
167
- recipientTokens = _j.sent();
168
- return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
169
- case 4:
170
- streamflowTreasuryTokens = _j.sent();
171
- partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
172
- return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
173
- case 5:
174
- partnerTokens = _j.sent();
175
- if (!isNative) return [3 /*break*/, 7];
176
- return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
177
- case 6:
178
- _g = _j.sent();
179
- return [3 /*break*/, 8];
180
- case 7:
181
- _g = [];
182
- _j.label = 8;
183
- case 8:
184
- nativeInstructions = _g;
185
- ixs.push((0, instructions_1.createStreamInstruction)({
186
- start: new bn_js_1.default(start),
187
- depositedAmount: depositedAmount,
188
- period: new bn_js_1.default(period),
189
- amountPerPeriod: amountPerPeriod,
190
- cliff: new bn_js_1.default(cliff),
191
- cliffAmount: cliffAmount,
192
- cancelableBySender: cancelableBySender,
193
- cancelableByRecipient: cancelableByRecipient,
194
- automaticWithdrawal: automaticWithdrawal,
195
- transferableBySender: transferableBySender,
196
- transferableByRecipient: transferableByRecipient,
197
- canTopup: canTopup,
198
- name: name,
199
- withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
200
- }, this.programId, {
201
- sender: sender.publicKey,
202
- senderTokens: senderTokens,
203
- recipient: new web3_js_1.PublicKey(recipient),
204
- metadata: metadata.publicKey,
205
- escrowTokens: escrowTokens,
206
- recipientTokens: recipientTokens,
207
- streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
208
- streamflowTreasuryTokens: streamflowTreasuryTokens,
209
- partner: partnerPublicKey,
210
- partnerTokens: partnerTokens,
211
- mint: new web3_js_1.PublicKey(mint),
212
- feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
213
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
214
- timelockProgram: this.programId,
215
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
216
- associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
217
- withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
218
- systemProgram: web3_js_1.SystemProgram.programId,
219
- }));
220
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
221
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
222
- case 9:
223
- hash = _j.sent();
224
- tx = (_h = new web3_js_1.Transaction({
225
- feePayer: sender.publicKey,
226
- blockhash: hash.blockhash,
227
- lastValidBlockHeight: hash.lastValidBlockHeight,
228
- })).add.apply(_h, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
229
- tx.partialSign(metadata);
230
- return [4 /*yield*/, this.sign(sender, tx, hash)];
231
- case 10:
232
- signature = _j.sent();
233
- return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadata.publicKey.toBase58() }];
234
- }
235
- });
236
- });
237
- };
238
- /**
239
- * Creates a new stream/vesting contract using unchecked instruction.
240
- *
241
- * Unchecked instruction differes from the regular in:
242
- * - does not check for initialized associated token account (wallets with no control over their ATA should not be used
243
- * as sender/recipient/partner or there are risks of funds being locked in the contract)
244
- * - initialized contract PDA off chain
245
- *
246
- * If you are not sure if you should use create or create_unchecked, go for create to be safer.
247
- */
248
- SolanaStreamClient.prototype.createUnchecked = function (_a, _b) {
249
- 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;
250
- var sender = _b.sender, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
251
- return __awaiter(this, void 0, void 0, function () {
252
- var mintPublicKey, recipientPublicKey, metadata, rentToExempt, createMetadataInstruction, _f, escrowTokens, senderTokens, partnerPublicKey, nativeInstructions, _g, createInstruction, commitment, ixs, hash, tx, signature;
253
- var _h;
254
- return __generator(this, function (_j) {
255
- switch (_j.label) {
256
- case 0:
257
- if (!sender.publicKey) {
258
- throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
259
- }
260
- mintPublicKey = new web3_js_1.PublicKey(mint);
261
- recipientPublicKey = new web3_js_1.PublicKey(recipient);
262
- metadata = web3_js_1.Keypair.generate();
263
- return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
264
- case 1:
265
- rentToExempt = _j.sent();
266
- createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
267
- programId: this.programId,
268
- space: METADATA_ACC_SIZE,
269
- lamports: rentToExempt,
270
- fromPubkey: sender === null || sender === void 0 ? void 0 : sender.publicKey,
271
- newAccountPubkey: metadata.publicKey,
272
- });
273
- return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
274
- case 2:
275
- _f = __read.apply(void 0, [_j.sent(), 1]), escrowTokens = _f[0];
276
- return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
277
- case 3:
278
- senderTokens = _j.sent();
279
- partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
280
- if (!isNative) return [3 /*break*/, 5];
281
- return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
282
- case 4:
283
- _g = _j.sent();
284
- return [3 /*break*/, 6];
285
- case 5:
286
- _g = [];
287
- _j.label = 6;
288
- case 6:
289
- nativeInstructions = _g;
290
- createInstruction = (0, instructions_1.createUncheckedStreamInstruction)({
291
- start: new bn_js_1.default(start),
292
- depositedAmount: depositedAmount,
293
- period: new bn_js_1.default(period),
294
- amountPerPeriod: amountPerPeriod,
295
- cliff: new bn_js_1.default(cliff),
296
- cliffAmount: cliffAmount,
297
- cancelableBySender: cancelableBySender,
298
- cancelableByRecipient: cancelableByRecipient,
299
- automaticWithdrawal: automaticWithdrawal,
300
- transferableBySender: transferableBySender,
301
- transferableByRecipient: transferableByRecipient,
302
- canTopup: canTopup,
303
- name: name,
304
- withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
305
- recipient: recipientPublicKey,
306
- partner: partnerPublicKey,
307
- }, this.programId, {
308
- sender: sender.publicKey,
309
- senderTokens: senderTokens,
310
- metadata: metadata.publicKey,
311
- escrowTokens: escrowTokens,
312
- mint: new web3_js_1.PublicKey(mint),
313
- feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
314
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
315
- timelockProgram: this.programId,
316
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
317
- withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
318
- systemProgram: web3_js_1.SystemProgram.programId,
319
- });
320
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
321
- ixs = [createMetadataInstruction, createInstruction];
322
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
323
- case 7:
324
- hash = _j.sent();
325
- tx = (_h = new web3_js_1.Transaction({
326
- feePayer: sender.publicKey,
327
- blockhash: hash.blockhash,
328
- lastValidBlockHeight: hash.lastValidBlockHeight,
329
- })).add.apply(_h, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
330
- tx.partialSign(metadata);
331
- return [4 /*yield*/, this.sign(sender, tx, hash)];
332
- case 8:
333
- signature = _j.sent();
334
- return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadata.publicKey.toBase58() }];
335
- }
336
- });
337
- });
338
- };
339
- /**
340
- * Creates multiple stream/vesting contracts.
341
- * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
342
- */
343
- SolanaStreamClient.prototype.createMultiple = function (data, _a) {
344
- var sender = _a.sender, _b = _a.isNative, isNative = _b === void 0 ? false : _b;
345
- return __awaiter(this, void 0, void 0, function () {
346
- var recipients, metadatas, metadataToRecipient, errors, signatures, batch, recipients_1, recipients_1_1, recipientData, _c, tx, metadata, metadataPubKey, e_1_1, totalDepositedAmount, nativeInstructions, commitment, hash, prepareTransaction, signedBatch, prepareTx, batchTransactionsCalls, responses, successes, failures, metadataIds;
347
- var e_1, _d, _e;
348
- var _this = this;
349
- return __generator(this, function (_f) {
350
- switch (_f.label) {
351
- case 0:
352
- recipients = data.recipients;
353
- if (!sender.publicKey) {
354
- throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
355
- }
356
- metadatas = [];
357
- metadataToRecipient = {};
358
- errors = [];
359
- signatures = [];
360
- batch = [];
361
- _f.label = 1;
362
- case 1:
363
- _f.trys.push([1, 6, 7, 8]);
364
- recipients_1 = __values(recipients), recipients_1_1 = recipients_1.next();
365
- _f.label = 2;
366
- case 2:
367
- if (!!recipients_1_1.done) return [3 /*break*/, 5];
368
- recipientData = recipients_1_1.value;
369
- return [4 /*yield*/, this.prepareStreamTransaction(recipientData, data, {
370
- sender: sender,
371
- })];
372
- case 3:
373
- _c = _f.sent(), tx = _c.tx, metadata = _c.metadata;
374
- metadataPubKey = metadata.publicKey.toBase58();
375
- metadataToRecipient[metadataPubKey] = recipientData;
376
- metadatas.push(metadata);
377
- batch.push({ tx: tx, recipient: recipientData.recipient });
378
- _f.label = 4;
379
- case 4:
380
- recipients_1_1 = recipients_1.next();
381
- return [3 /*break*/, 2];
382
- case 5: return [3 /*break*/, 8];
383
- case 6:
384
- e_1_1 = _f.sent();
385
- e_1 = { error: e_1_1 };
386
- return [3 /*break*/, 8];
387
- case 7:
388
- try {
389
- if (recipients_1_1 && !recipients_1_1.done && (_d = recipients_1.return)) _d.call(recipients_1);
390
- }
391
- finally { if (e_1) throw e_1.error; }
392
- return [7 /*endfinally*/];
393
- case 8:
394
- if (!isNative) return [3 /*break*/, 11];
395
- totalDepositedAmount = recipients.reduce(function (acc, recipient) { return recipient.amount.add(acc); }, new bn_js_1.default(0));
396
- return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
397
- case 9:
398
- nativeInstructions = _f.sent();
399
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
400
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
401
- case 10:
402
- hash = _f.sent();
403
- prepareTransaction = (_e = new web3_js_1.Transaction({
404
- feePayer: sender.publicKey,
405
- blockhash: hash.blockhash,
406
- lastValidBlockHeight: hash.lastValidBlockHeight,
407
- })).add.apply(_e, __spreadArray([], __read(nativeInstructions), false));
408
- batch.push({ tx: prepareTransaction, recipient: sender.publicKey.toBase58() });
409
- _f.label = 11;
410
- case 11: return [4 /*yield*/, (0, utils_1.signAllTransactionWithRecipients)(sender, batch)];
411
- case 12:
412
- signedBatch = _f.sent();
413
- signedBatch.forEach(function (item, index) {
414
- item.tx.lastValidBlockHeight = batch[index].tx.lastValidBlockHeight;
415
- });
416
- if (!isNative) return [3 /*break*/, 14];
417
- prepareTx = signedBatch.pop();
418
- return [4 /*yield*/, (0, utils_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx)];
419
- case 13:
420
- _f.sent();
421
- _f.label = 14;
422
- case 14:
423
- batchTransactionsCalls = signedBatch.map(function (el) {
424
- return (0, utils_1.sendAndConfirmStreamRawTransaction)(_this.connection, el);
425
- });
426
- return [4 /*yield*/, Promise.allSettled(batchTransactionsCalls)];
427
- case 15:
428
- responses = _f.sent();
429
- successes = responses
430
- .filter(function (el) { return el.status === "fulfilled"; })
431
- .map(function (el) { return el.value; });
432
- signatures.push.apply(signatures, __spreadArray([], __read(successes.map(function (el) { return el.signature; })), false));
433
- failures = responses
434
- .filter(function (el) { return el.status === "rejected"; })
435
- .map(function (el) { return (__assign(__assign({}, el.reason), { contractErrorCode: _this.extractErrorCode(el.reason.error) || undefined })); });
436
- errors.push.apply(errors, __spreadArray([], __read(failures), false));
437
- metadataIds = metadatas.map(function (pk) { return pk.publicKey.toBase58(); });
438
- return [2 /*return*/, { txs: signatures, metadatas: metadataIds, metadataToRecipient: metadataToRecipient, errors: errors }];
439
- }
440
- });
441
- });
442
- };
443
- /**
444
- * Attempts withdrawing from the specified stream.
445
- */
446
- SolanaStreamClient.prototype.withdraw = function (_a, _b) {
447
- var id = _a.id, amount = _a.amount;
448
- var invoker = _b.invoker;
449
- return __awaiter(this, void 0, void 0, function () {
450
- var ixs, streamPublicKey, escrow, data, streamflowTreasuryTokens, partnerTokens, commitment, hash, tx, signature;
451
- var _c;
452
- return __generator(this, function (_d) {
453
- switch (_d.label) {
454
- case 0:
455
- if (!invoker.publicKey) {
456
- throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
457
- }
458
- ixs = [];
459
- streamPublicKey = new web3_js_1.PublicKey(id);
460
- return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
461
- case 1:
462
- escrow = _d.sent();
463
- if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
464
- throw new Error("Couldn't get account info");
465
- }
466
- data = (0, utils_1.decodeStream)(escrow.data);
467
- return [4 /*yield*/, (0, utils_1.ata)(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
468
- case 2:
469
- streamflowTreasuryTokens = _d.sent();
470
- return [4 /*yield*/, (0, utils_1.ata)(data.mint, data.partner)];
471
- case 3:
472
- partnerTokens = _d.sent();
473
- ixs.push((0, instructions_1.withdrawStreamInstruction)(amount, this.programId, {
474
- authority: invoker.publicKey,
475
- recipient: invoker.publicKey,
476
- recipientTokens: data.recipientTokens,
477
- metadata: streamPublicKey,
478
- escrowTokens: data.escrowTokens,
479
- streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
480
- streamflowTreasuryTokens: streamflowTreasuryTokens,
481
- partner: data.partner,
482
- partnerTokens: partnerTokens,
483
- mint: data.mint,
484
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
485
- }));
486
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
487
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
488
- case 4:
489
- hash = _d.sent();
490
- tx = (_c = new web3_js_1.Transaction({
491
- feePayer: invoker.publicKey,
492
- blockhash: hash.blockhash,
493
- lastValidBlockHeight: hash.lastValidBlockHeight,
494
- })).add.apply(_c, __spreadArray([], __read(ixs), false));
495
- return [4 /*yield*/, this.sign(invoker, tx, hash)];
496
- case 5:
497
- signature = _d.sent();
498
- return [2 /*return*/, { ixs: ixs, txId: signature }];
499
- }
500
- });
501
- });
502
- };
503
- /**
504
- * Attempts canceling the specified stream.
505
- */
506
- SolanaStreamClient.prototype.cancel = function (_a, _b) {
507
- var id = _a.id;
508
- var invoker = _b.invoker;
509
- return __awaiter(this, void 0, void 0, function () {
510
- var streamPublicKey, escrowAcc, data, streamflowTreasuryTokens, partnerTokens, ixs, commitment, hash, tx, signature;
511
- var _c;
512
- return __generator(this, function (_d) {
513
- switch (_d.label) {
514
- case 0:
515
- if (!invoker.publicKey) {
516
- throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
517
- }
518
- streamPublicKey = new web3_js_1.PublicKey(id);
519
- return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
520
- case 1:
521
- escrowAcc = _d.sent();
522
- if (!(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data)) {
523
- throw new Error("Couldn't get account info");
524
- }
525
- data = (0, utils_1.decodeStream)(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data);
526
- return [4 /*yield*/, (0, utils_1.ata)(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
527
- case 2:
528
- streamflowTreasuryTokens = _d.sent();
529
- return [4 /*yield*/, (0, utils_1.ata)(data.mint, data.partner)];
530
- case 3:
531
- partnerTokens = _d.sent();
532
- ixs = [];
533
- ixs.push((0, instructions_1.cancelStreamInstruction)(this.programId, {
534
- authority: invoker.publicKey,
535
- sender: data.sender,
536
- senderTokens: data.senderTokens,
537
- recipient: data.recipient,
538
- recipientTokens: data.recipientTokens,
539
- metadata: streamPublicKey,
540
- escrowTokens: data.escrowTokens,
541
- streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
542
- streamflowTreasuryTokens: streamflowTreasuryTokens,
543
- partner: data.partner,
544
- partnerTokens: partnerTokens,
545
- mint: data.mint,
546
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
547
- }));
548
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
549
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
550
- case 4:
551
- hash = _d.sent();
552
- tx = (_c = new web3_js_1.Transaction({
553
- feePayer: invoker.publicKey,
554
- blockhash: hash.blockhash,
555
- lastValidBlockHeight: hash.lastValidBlockHeight,
556
- })).add.apply(_c, __spreadArray([], __read(ixs), false));
557
- return [4 /*yield*/, this.sign(invoker, tx, hash)];
558
- case 5:
559
- signature = _d.sent();
560
- return [2 /*return*/, { ixs: ixs, txId: signature }];
561
- }
562
- });
563
- });
564
- };
565
- /**
566
- * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
567
- * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
568
- */
569
- SolanaStreamClient.prototype.transfer = function (_a, _b) {
570
- var id = _a.id, newRecipientString = _a.newRecipient;
571
- var invoker = _b.invoker;
572
- return __awaiter(this, void 0, void 0, function () {
573
- var ixs, stream, newRecipient, escrow, mint, newRecipientTokens, commitment, hash, tx, signature;
574
- var _c;
575
- return __generator(this, function (_d) {
576
- switch (_d.label) {
577
- case 0:
578
- if (!invoker.publicKey) {
579
- throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
580
- }
581
- ixs = [];
582
- stream = new web3_js_1.PublicKey(id);
583
- newRecipient = new web3_js_1.PublicKey(newRecipientString);
584
- return [4 /*yield*/, this.connection.getAccountInfo(stream)];
585
- case 1:
586
- escrow = _d.sent();
587
- if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
588
- throw new Error("Couldn't get account info");
589
- }
590
- mint = (0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data).mint;
591
- return [4 /*yield*/, (0, utils_1.ata)(mint, newRecipient)];
592
- case 2:
593
- newRecipientTokens = _d.sent();
594
- ixs.push((0, instructions_1.transferStreamInstruction)(this.programId, {
595
- authority: invoker.publicKey,
596
- newRecipient: newRecipient,
597
- newRecipientTokens: newRecipientTokens,
598
- metadata: stream,
599
- mint: mint,
600
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
601
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
602
- associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
603
- systemProgram: web3_js_1.SystemProgram.programId,
604
- }));
605
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
606
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
607
- case 3:
608
- hash = _d.sent();
609
- tx = (_c = new web3_js_1.Transaction({
610
- feePayer: invoker.publicKey,
611
- blockhash: hash.blockhash,
612
- lastValidBlockHeight: hash.lastValidBlockHeight,
613
- })).add.apply(_c, __spreadArray([], __read(ixs), false));
614
- return [4 /*yield*/, this.sign(invoker, tx, hash)];
615
- case 4:
616
- signature = _d.sent();
617
- return [2 /*return*/, { ixs: ixs, txId: signature }];
618
- }
619
- });
620
- });
621
- };
622
- /**
623
- * Tops up stream account with specified amount.
624
- */
625
- SolanaStreamClient.prototype.topup = function (_a, _b) {
626
- var id = _a.id, amount = _a.amount;
627
- var invoker = _b.invoker, isNative = _b.isNative;
628
- return __awaiter(this, void 0, void 0, function () {
629
- var ixs, streamPublicKey, escrow, _c, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, nativeInstructions, _d, commitment, hash, tx, signature;
630
- var _e;
631
- return __generator(this, function (_f) {
632
- switch (_f.label) {
633
- case 0:
634
- if (!invoker.publicKey) {
635
- throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
636
- }
637
- ixs = [];
638
- streamPublicKey = new web3_js_1.PublicKey(id);
639
- return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
640
- case 1:
641
- escrow = _f.sent();
642
- if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
643
- throw new Error("Couldn't get account info");
644
- }
645
- _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;
646
- return [4 /*yield*/, (0, utils_1.ata)(mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
647
- case 2:
648
- streamflowTreasuryTokens = _f.sent();
649
- return [4 /*yield*/, (0, utils_1.ata)(mint, partner)];
650
- case 3:
651
- partnerTokens = _f.sent();
652
- if (!isNative) return [3 /*break*/, 5];
653
- return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, invoker.publicKey, amount)];
654
- case 4:
655
- _d = _f.sent();
656
- return [3 /*break*/, 6];
657
- case 5:
658
- _d = [];
659
- _f.label = 6;
660
- case 6:
661
- nativeInstructions = _d;
662
- ixs.push((0, instructions_1.topupStreamInstruction)(amount, this.programId, {
663
- sender: invoker.publicKey,
664
- senderTokens: senderTokens,
665
- metadata: streamPublicKey,
666
- escrowTokens: escrowTokens,
667
- streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
668
- streamflowTreasuryTokens: streamflowTreasuryTokens,
669
- partner: partner,
670
- partnerTokens: partnerTokens,
671
- mint: mint,
672
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
673
- withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
674
- systemProgram: web3_js_1.SystemProgram.programId,
675
- }));
676
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
677
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
678
- case 7:
679
- hash = _f.sent();
680
- tx = (_e = new web3_js_1.Transaction({
681
- feePayer: invoker.publicKey,
682
- blockhash: hash.blockhash,
683
- lastValidBlockHeight: hash.lastValidBlockHeight,
684
- })).add.apply(_e, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
685
- return [4 /*yield*/, this.sign(invoker, tx, hash)];
686
- case 8:
687
- signature = _f.sent();
688
- return [2 /*return*/, { ixs: ixs, txId: signature }];
689
- }
690
- });
691
- });
692
- };
693
- /**
694
- * Fetch stream data by its id (address).
695
- */
696
- SolanaStreamClient.prototype.getOne = function (_a) {
697
- var id = _a.id;
698
- return __awaiter(this, void 0, void 0, function () {
699
- var escrow;
700
- return __generator(this, function (_b) {
701
- switch (_b.label) {
702
- case 0: return [4 /*yield*/, this.connection.getAccountInfo(new web3_js_1.PublicKey(id), constants_1.TX_FINALITY_CONFIRMED)];
703
- case 1:
704
- escrow = _b.sent();
705
- if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
706
- throw new Error("Couldn't get account info.");
707
- }
708
- return [2 /*return*/, new types_1.Contract((0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data))];
709
- }
710
- });
711
- });
712
- };
713
- /**
714
- * Fetch streams/contracts by providing direction.
715
- * Streams are sorted by start time in ascending order.
716
- */
717
- SolanaStreamClient.prototype.get = function (_a) {
718
- var address = _a.address, _b = _a.type, type = _b === void 0 ? types_2.StreamType.All : _b, _c = _a.direction, direction = _c === void 0 ? types_2.StreamDirection.All : _c;
719
- return __awaiter(this, void 0, void 0, function () {
720
- var publicKey, accounts, outgoingAccounts, incomingAccounts, offset, streams, sortedStreams;
721
- return __generator(this, function (_d) {
722
- switch (_d.label) {
723
- case 0:
724
- publicKey = new web3_js_1.PublicKey(address);
725
- accounts = [];
726
- if (!(direction === "all")) return [3 /*break*/, 3];
727
- return [4 /*yield*/, (0, utils_1.getProgramAccounts)(this.connection, publicKey, constants_1.STREAM_STRUCT_OFFSET_SENDER, this.programId)];
728
- case 1:
729
- outgoingAccounts = _d.sent();
730
- return [4 /*yield*/, (0, utils_1.getProgramAccounts)(this.connection, publicKey, constants_1.STREAM_STRUCT_OFFSET_RECIPIENT, this.programId)];
731
- case 2:
732
- incomingAccounts = _d.sent();
733
- accounts = __spreadArray(__spreadArray([], __read(outgoingAccounts), false), __read(incomingAccounts), false);
734
- return [3 /*break*/, 5];
735
- case 3:
736
- offset = direction === "outgoing" ? constants_1.STREAM_STRUCT_OFFSET_SENDER : constants_1.STREAM_STRUCT_OFFSET_RECIPIENT;
737
- return [4 /*yield*/, (0, utils_1.getProgramAccounts)(this.connection, publicKey, offset, this.programId)];
738
- case 4:
739
- accounts = _d.sent();
740
- _d.label = 5;
741
- case 5:
742
- streams = {};
743
- accounts.forEach(function (account) {
744
- var _a;
745
- var decoded = new types_1.Contract((0, utils_1.decodeStream)(account.account.data));
746
- streams = __assign(__assign({}, streams), (_a = {}, _a[account.pubkey.toBase58()] = decoded, _a));
747
- });
748
- sortedStreams = Object.entries(streams).sort(function (_a, _b) {
749
- var _c = __read(_a, 2), stream1 = _c[1];
750
- var _d = __read(_b, 2), stream2 = _d[1];
751
- return stream2.start - stream1.start;
752
- });
753
- if (type === "all")
754
- return [2 /*return*/, sortedStreams];
755
- return [2 /*return*/, sortedStreams.filter(function (stream) { return stream[1].type === type; })];
756
- }
757
- });
758
- });
759
- };
760
- SolanaStreamClient.prototype.sign = function (invoker, tx, hash) {
761
- return __awaiter(this, void 0, void 0, function () {
762
- var signedTx, rawTx, confirmationStrategy, signature;
763
- return __generator(this, function (_a) {
764
- switch (_a.label) {
765
- case 0:
766
- if (!(0, utils_1.isSignerWallet)(invoker)) return [3 /*break*/, 2];
767
- return [4 /*yield*/, invoker.signTransaction(tx)];
768
- case 1:
769
- signedTx = _a.sent();
770
- return [3 /*break*/, 3];
771
- case 2:
772
- tx.partialSign(invoker);
773
- signedTx = tx;
774
- _a.label = 3;
775
- case 3:
776
- rawTx = signedTx.serialize();
777
- if (!hash.lastValidBlockHeight || !signedTx.signature || !hash.blockhash)
778
- throw Error("Error with transaction parameters.");
779
- confirmationStrategy = {
780
- lastValidBlockHeight: hash.lastValidBlockHeight,
781
- signature: bs58_1.default.encode(signedTx.signature),
782
- blockhash: hash.blockhash,
783
- };
784
- return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, rawTx, confirmationStrategy)];
785
- case 4:
786
- signature = _a.sent();
787
- return [2 /*return*/, signature];
788
- }
789
- });
790
- });
791
- };
792
- /**
793
- * Attempts updating the stream auto withdrawal params and amount per period
794
- */
795
- SolanaStreamClient.prototype.update = function (data, _a) {
796
- var invoker = _a.invoker;
797
- return __awaiter(this, void 0, void 0, function () {
798
- var streamPublicKey, escrow, updateIx, commitment, hash, tx, signature;
799
- return __generator(this, function (_b) {
800
- switch (_b.label) {
801
- case 0:
802
- if (!invoker.publicKey) {
803
- throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
804
- }
805
- streamPublicKey = new web3_js_1.PublicKey(data.id);
806
- return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
807
- case 1:
808
- escrow = _b.sent();
809
- if (!escrow) {
810
- throw new Error("Couldn't get account info");
811
- }
812
- updateIx = (0, instructions_1.updateStreamInstruction)(data, this.programId, {
813
- authority: invoker.publicKey,
814
- metadata: streamPublicKey,
815
- withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
816
- systemProgram: web3_js_1.SystemProgram.programId,
817
- });
818
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
819
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
820
- case 2:
821
- hash = _b.sent();
822
- tx = new web3_js_1.Transaction({
823
- feePayer: invoker.publicKey,
824
- blockhash: hash.blockhash,
825
- lastValidBlockHeight: hash.lastValidBlockHeight,
826
- }).add(updateIx);
827
- return [4 /*yield*/, this.sign(invoker, tx, hash)];
828
- case 3:
829
- signature = _b.sent();
830
- return [2 /*return*/, {
831
- ixs: [updateIx],
832
- txId: signature,
833
- }];
834
- }
835
- });
836
- });
837
- };
838
- SolanaStreamClient.prototype.extractErrorCode = function (err) {
839
- var _a;
840
- return (0, utils_1.extractSolanaErrorCode)((_a = err.toString()) !== null && _a !== void 0 ? _a : "Unknown error!");
841
- };
842
- /**
843
- * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
844
- */
845
- SolanaStreamClient.prototype.prepareStreamTransaction = function (recipient, streamParams, solanaExtendedConfig) {
846
- return __awaiter(this, void 0, void 0, function () {
847
- var mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, partner, sender, ixs, commitment, recipientPublicKey, mintPublicKey, metadata, _c, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, hash, tx;
848
- var _d;
849
- return __generator(this, function (_e) {
850
- switch (_e.label) {
851
- case 0:
852
- 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, partner = streamParams.partner;
853
- sender = solanaExtendedConfig.sender;
854
- if (!sender.publicKey) {
855
- throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
856
- }
857
- ixs = [];
858
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
859
- recipientPublicKey = new web3_js_1.PublicKey(recipient.recipient);
860
- mintPublicKey = new web3_js_1.PublicKey(mint);
861
- metadata = web3_js_1.Keypair.generate();
862
- _c = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId), 1), escrowTokens = _c[0];
863
- return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
864
- case 1:
865
- senderTokens = _e.sent();
866
- return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
867
- case 2:
868
- recipientTokens = _e.sent();
869
- return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
870
- case 3:
871
- streamflowTreasuryTokens = _e.sent();
872
- partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
873
- return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
874
- case 4:
875
- partnerTokens = _e.sent();
876
- ixs.push((0, instructions_1.createStreamInstruction)({
877
- start: new bn_js_1.default(start),
878
- depositedAmount: recipient.amount,
879
- period: new bn_js_1.default(period),
880
- amountPerPeriod: recipient.amountPerPeriod,
881
- cliff: new bn_js_1.default(cliff),
882
- cliffAmount: recipient.cliffAmount,
883
- cancelableBySender: cancelableBySender,
884
- cancelableByRecipient: cancelableByRecipient,
885
- automaticWithdrawal: automaticWithdrawal,
886
- transferableBySender: transferableBySender,
887
- transferableByRecipient: transferableByRecipient,
888
- canTopup: canTopup,
889
- name: recipient.name,
890
- withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
891
- }, this.programId, {
892
- sender: sender.publicKey,
893
- senderTokens: senderTokens,
894
- recipient: new web3_js_1.PublicKey(recipient.recipient),
895
- metadata: metadata.publicKey,
896
- escrowTokens: escrowTokens,
897
- recipientTokens: recipientTokens,
898
- streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
899
- streamflowTreasuryTokens: streamflowTreasuryTokens,
900
- partner: partnerPublicKey,
901
- partnerTokens: partnerTokens,
902
- mint: new web3_js_1.PublicKey(mint),
903
- feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
904
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
905
- timelockProgram: this.programId,
906
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
907
- associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
908
- withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
909
- systemProgram: web3_js_1.SystemProgram.programId,
910
- }));
911
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
912
- case 5:
913
- hash = _e.sent();
914
- tx = (_d = new web3_js_1.Transaction({
915
- feePayer: sender.publicKey,
916
- blockhash: hash.blockhash,
917
- lastValidBlockHeight: hash.lastValidBlockHeight,
918
- })).add.apply(_d, __spreadArray([], __read(ixs), false));
919
- tx.partialSign(metadata);
920
- return [2 /*return*/, { tx: tx, metadata: metadata }];
921
- }
922
- });
923
- });
924
- };
925
- return SolanaStreamClient;
926
- }(BaseStreamClient_1.BaseStreamClient));
927
- exports.default = SolanaStreamClient;