@streamflow/stream 4.0.0-Alpha.0 → 4.0.0-Alpha.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 (47) hide show
  1. package/dist/__tests__/aptos/streamClient.spec.js +4 -4
  2. package/dist/aptos/StreamClient.d.ts +6 -5
  3. package/dist/aptos/StreamClient.js +53 -58
  4. package/dist/aptos/constants.js +2 -2
  5. package/dist/aptos/types.d.ts +135 -0
  6. package/dist/aptos/types.js +63 -0
  7. package/dist/common/BaseStreamClient.d.ts +10 -0
  8. package/dist/common/BaseStreamClient.js +9 -0
  9. package/dist/common/GenericStreamClient.d.ts +34 -0
  10. package/dist/common/GenericStreamClient.js +103 -0
  11. package/dist/common/types.d.ts +4 -9
  12. package/dist/common/types.js +6 -7
  13. package/dist/index.d.ts +1 -0
  14. package/dist/index.js +6 -1
  15. package/dist/solana/StreamClient.d.ts +3 -2
  16. package/dist/solana/StreamClient.js +2 -1
  17. package/dist/solana/index.d.ts +2 -0
  18. package/dist/solana/index.js +16 -1
  19. package/dist/solana/layout.d.ts +6 -6
  20. package/dist/solana/layout.js +100 -75
  21. package/package.json +3 -3
  22. package/dist/Stream.d.ts +0 -87
  23. package/dist/Stream.js +0 -503
  24. package/dist/StreamClient.d.ts +0 -145
  25. package/dist/StreamClient.js +0 -1031
  26. package/dist/__tests__/test_dependencies/airdrop/airdrop-request.d.ts +0 -2
  27. package/dist/__tests__/test_dependencies/airdrop/airdrop-request.js +0 -67
  28. package/dist/__tests__/test_dependencies/airdrop/airdrop.d.ts +0 -6
  29. package/dist/__tests__/test_dependencies/airdrop/airdrop.js +0 -215
  30. package/dist/__tests__/test_dependencies/constants/index.d.ts +0 -122
  31. package/dist/__tests__/test_dependencies/constants/index.js +0 -158
  32. package/dist/__tests__/test_dependencies/idl/airdrop.d.ts +0 -27
  33. package/dist/__tests__/test_dependencies/idl/airdrop.js +0 -171
  34. package/dist/constants.d.ts +0 -18
  35. package/dist/constants.js +0 -23
  36. package/dist/idl/timelock.d.ts +0 -22
  37. package/dist/idl/timelock.js +0 -422
  38. package/dist/instructionTypes.d.ts +0 -81
  39. package/dist/instructionTypes.js +0 -2
  40. package/dist/instructions.d.ts +0 -131
  41. package/dist/instructions.js +0 -379
  42. package/dist/layout.d.ts +0 -22
  43. package/dist/layout.js +0 -99
  44. package/dist/types.d.ts +0 -317
  45. package/dist/types.js +0 -91
  46. package/dist/utils.d.ts +0 -19
  47. package/dist/utils.js +0 -126
package/dist/Stream.js DELETED
@@ -1,503 +0,0 @@
1
- "use strict";
2
- // Version 1 of the SDK that uses Anchor.
3
- var __assign = (this && this.__assign) || function () {
4
- __assign = Object.assign || function(t) {
5
- for (var s, i = 1, n = arguments.length; i < n; i++) {
6
- s = arguments[i];
7
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
- t[p] = s[p];
9
- }
10
- return t;
11
- };
12
- return __assign.apply(this, arguments);
13
- };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
- var __generator = (this && this.__generator) || function (thisArg, body) {
24
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
25
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26
- function verb(n) { return function (v) { return step([n, v]); }; }
27
- function step(op) {
28
- if (f) throw new TypeError("Generator is already executing.");
29
- while (_) try {
30
- 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;
31
- if (y = 0, t) op = [op[0] & 2, t.value];
32
- switch (op[0]) {
33
- case 0: case 1: t = op; break;
34
- case 4: _.label++; return { value: op[1], done: false };
35
- case 5: _.label++; y = op[1]; op = [0]; continue;
36
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
37
- default:
38
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
39
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
40
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
41
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
42
- if (t[2]) _.ops.pop();
43
- _.trys.pop(); continue;
44
- }
45
- op = body.call(thisArg, _);
46
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
47
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
- }
49
- };
50
- var __read = (this && this.__read) || function (o, n) {
51
- var m = typeof Symbol === "function" && o[Symbol.iterator];
52
- if (!m) return o;
53
- var i = m.call(o), r, ar = [], e;
54
- try {
55
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
56
- }
57
- catch (error) { e = { error: error }; }
58
- finally {
59
- try {
60
- if (r && !r.done && (m = i["return"])) m.call(i);
61
- }
62
- finally { if (e) throw e.error; }
63
- }
64
- return ar;
65
- };
66
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
67
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
68
- if (ar || !(i in from)) {
69
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
70
- ar[i] = from[i];
71
- }
72
- }
73
- return to.concat(ar || Array.prototype.slice.call(from));
74
- };
75
- var __importDefault = (this && this.__importDefault) || function (mod) {
76
- return (mod && mod.__esModule) ? mod : { "default": mod };
77
- };
78
- Object.defineProperty(exports, "__esModule", { value: true });
79
- var bn_js_1 = __importDefault(require("bn.js"));
80
- var buffer_1 = require("buffer");
81
- var anchor_1 = require("@project-serum/anchor");
82
- var spl_token_1 = require("@solana/spl-token");
83
- var web3_js_1 = require("@solana/web3.js");
84
- var types_1 = require("./types");
85
- var utils_1 = require("./utils");
86
- var constants_1 = require("./constants");
87
- var timelock_1 = __importDefault(require("./idl/timelock"));
88
- var encoder = new TextEncoder();
89
- var initProgram = function (connection, wallet, cluster) {
90
- var provider = new anchor_1.Provider(connection, wallet, {});
91
- return new anchor_1.Program(timelock_1.default, constants_1.PROGRAM_ID[cluster], provider);
92
- };
93
- var Stream = /** @class */ (function () {
94
- function Stream() {
95
- }
96
- /**
97
- * Creates a new stream/vesting contract.
98
- * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
99
- * @param {CreateStreamParams} data
100
- * @param {Connection} data.connection - A connection to the cluster.
101
- * @param {Wallet} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
102
- * @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
103
- * @param {string} data.mint - SPL Token mint.
104
- * @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
105
- * @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
106
- * @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
107
- * @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
108
- * @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
109
- * @param {BN} data.amountPerPeriod - Amount unlocked per each period.
110
- * @param {string} data.name - Stream name/subject.
111
- * @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
112
- * @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
113
- * @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
114
- * @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
115
- * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
116
- * @param {boolean} [data.automaticWithdrawal = false] - Whether or not a 3rd party can initiate withdraw in the name of recipient.
117
- * @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.
118
- * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
119
- * @param {ClusterExtended} [data.cluster = Cluster.Mainnet] - Cluster: devnet, mainnet-beta, testnet or local (optional).
120
- */
121
- Stream.create = function (_a) {
122
- var connection = _a.connection, 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 ? "" : _d, _e = _a.cluster, cluster = _e === void 0 ? types_1.Cluster.Mainnet : _e;
123
- return __awaiter(this, void 0, void 0, function () {
124
- var program, mintPublicKey, recipientPublicKey, metadata, _f, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, signers, nameUtf8EncodedArr, tx;
125
- return __generator(this, function (_g) {
126
- switch (_g.label) {
127
- case 0:
128
- program = initProgram(connection, sender, cluster);
129
- mintPublicKey = new web3_js_1.PublicKey(mint);
130
- recipientPublicKey = new web3_js_1.PublicKey(recipient);
131
- metadata = web3_js_1.Keypair.generate();
132
- return [4 /*yield*/, anchor_1.web3.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], program.programId)];
133
- case 1:
134
- _f = __read.apply(void 0, [_g.sent(), 1]), escrowTokens = _f[0];
135
- return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
136
- case 2:
137
- senderTokens = _g.sent();
138
- return [4 /*yield*/, ata(mintPublicKey, recipientPublicKey)];
139
- case 3:
140
- recipientTokens = _g.sent();
141
- return [4 /*yield*/, ata(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
142
- case 4:
143
- streamflowTreasuryTokens = _g.sent();
144
- partnerPublicKey = partner
145
- ? new web3_js_1.PublicKey(partner)
146
- : sender.publicKey;
147
- return [4 /*yield*/, ata(mintPublicKey, partnerPublicKey)];
148
- case 5:
149
- partnerTokens = _g.sent();
150
- signers = [metadata];
151
- nameUtf8EncodedArr = encoder.encode(name);
152
- return [4 /*yield*/, program.rpc.create(
153
- // Order of the parameters must match the ones in the program
154
- new bn_js_1.default(start), depositedAmount, new bn_js_1.default(period), amountPerPeriod, new bn_js_1.default(cliff), cliffAmount, cancelableBySender, cancelableByRecipient, automaticWithdrawal, transferableBySender, transferableByRecipient, canTopup, nameUtf8EncodedArr, new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period), {
155
- accounts: {
156
- sender: sender.publicKey,
157
- senderTokens: senderTokens,
158
- recipient: new web3_js_1.PublicKey(recipient),
159
- metadata: metadata.publicKey,
160
- escrowTokens: escrowTokens,
161
- recipientTokens: recipientTokens,
162
- streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
163
- streamflowTreasuryTokens: streamflowTreasuryTokens,
164
- partner: partnerPublicKey,
165
- partnerTokens: partnerTokens,
166
- mint: new web3_js_1.PublicKey(mint),
167
- feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
168
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
169
- timelockProgram: program.programId,
170
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
171
- associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
172
- withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
173
- systemProgram: web3_js_1.SystemProgram.programId,
174
- },
175
- signers: signers,
176
- })];
177
- case 6:
178
- tx = _g.sent();
179
- return [2 /*return*/, { tx: tx, id: metadata.publicKey.toBase58() }];
180
- }
181
- });
182
- });
183
- };
184
- /**
185
- * Attempts withdrawal from the specified stream.
186
- * @param {WithdrawStreamParams} data
187
- * @param {Connection} data.connection - A connection to the cluster.
188
- * @param {Wallet} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (recipient) or transaction will fail.
189
- * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be withdrawn from.
190
- * @param {BN} data.amount - Requested amount (in the smallest units) to withdraw (while streaming). If stream is completed, the whole amount will be withdrawn.
191
- * @param {ClusterExtended} [data.cluster = Cluster.Mainnet] - Cluster: devnet, mainnet-beta, testnet or local (optional).
192
- */
193
- Stream.withdraw = function (_a) {
194
- var connection = _a.connection, invoker = _a.invoker, id = _a.id, amount = _a.amount, _b = _a.cluster, cluster = _b === void 0 ? types_1.Cluster.Mainnet : _b;
195
- return __awaiter(this, void 0, void 0, function () {
196
- var program, streamPublicKey, escrow, data, streamflowTreasuryTokens, partnerTokens, tx;
197
- return __generator(this, function (_c) {
198
- switch (_c.label) {
199
- case 0:
200
- program = initProgram(connection, invoker, cluster);
201
- streamPublicKey = new web3_js_1.PublicKey(id);
202
- return [4 /*yield*/, connection.getAccountInfo(streamPublicKey)];
203
- case 1:
204
- escrow = _c.sent();
205
- if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
206
- throw new Error("Couldn't get account info");
207
- }
208
- data = (0, utils_1.decodeStream)(escrow.data);
209
- return [4 /*yield*/, ata(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
210
- case 2:
211
- streamflowTreasuryTokens = _c.sent();
212
- return [4 /*yield*/, ata(data.mint, data.partner)];
213
- case 3:
214
- partnerTokens = _c.sent();
215
- return [4 /*yield*/, program.rpc.withdraw(amount, {
216
- accounts: {
217
- authority: invoker.publicKey,
218
- recipient: data.recipient,
219
- recipientTokens: data.recipientTokens,
220
- metadata: streamPublicKey,
221
- escrowTokens: data.escrowTokens,
222
- streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
223
- streamflowTreasuryTokens: streamflowTreasuryTokens,
224
- partner: data.partner,
225
- partnerTokens: partnerTokens,
226
- mint: data.mint,
227
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
228
- },
229
- })];
230
- case 4:
231
- tx = _c.sent();
232
- return [2 /*return*/, { tx: tx }];
233
- }
234
- });
235
- });
236
- };
237
- /**
238
- * Attempts canceling the specified stream.
239
- * @param {CancelStreamParams} data
240
- * @param {Connection} data.connection - A connection to the cluster.
241
- * @param {Wallet} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
242
- * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be canceled.
243
- * @param {ClusterExtended} [data.cluster = Cluster.Mainnet] - Cluster: devnet, mainnet-beta, testnet or local (optional).
244
- */
245
- Stream.cancel = function (_a) {
246
- var connection = _a.connection, invoker = _a.invoker, id = _a.id, _b = _a.cluster, cluster = _b === void 0 ? types_1.Cluster.Mainnet : _b;
247
- return __awaiter(this, void 0, void 0, function () {
248
- var program, streamPublicKey, escrow_acc, data, streamflowTreasuryTokens, partnerTokens, tx;
249
- return __generator(this, function (_c) {
250
- switch (_c.label) {
251
- case 0:
252
- program = initProgram(connection, invoker, cluster);
253
- streamPublicKey = new web3_js_1.PublicKey(id);
254
- return [4 /*yield*/, connection.getAccountInfo(streamPublicKey)];
255
- case 1:
256
- escrow_acc = _c.sent();
257
- if (!(escrow_acc === null || escrow_acc === void 0 ? void 0 : escrow_acc.data)) {
258
- throw new Error("Couldn't get account info");
259
- }
260
- data = (0, utils_1.decodeStream)(escrow_acc === null || escrow_acc === void 0 ? void 0 : escrow_acc.data);
261
- return [4 /*yield*/, ata(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
262
- case 2:
263
- streamflowTreasuryTokens = _c.sent();
264
- return [4 /*yield*/, ata(data.mint, data.partner)];
265
- case 3:
266
- partnerTokens = _c.sent();
267
- return [4 /*yield*/, program.rpc.cancel({
268
- accounts: {
269
- authority: invoker.publicKey,
270
- sender: data.sender,
271
- senderTokens: data.senderTokens,
272
- recipient: data.recipient,
273
- recipientTokens: data.recipientTokens,
274
- metadata: streamPublicKey,
275
- escrowTokens: data.escrowTokens,
276
- streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
277
- streamflowTreasuryTokens: streamflowTreasuryTokens,
278
- partner: data.partner,
279
- partnerTokens: partnerTokens,
280
- mint: data.mint,
281
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
282
- },
283
- })];
284
- case 4:
285
- tx = _c.sent();
286
- return [2 /*return*/, { tx: tx }];
287
- }
288
- });
289
- });
290
- };
291
- /**
292
- * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
293
- * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
294
- * @param {TransferStreamParams} data
295
- * @param {Connection} data.connection - A connection to the cluster.
296
- * @param {Wallet} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
297
- * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be transferred.
298
- * @param {string} data.recipientId - Address of a new recipient.
299
- * @param {ClusterExtended} [data.cluster = Cluster.Mainnet] - Cluster: devnet, mainnet-beta, testnet or local (optional).
300
- */
301
- Stream.transfer = function (_a) {
302
- var connection = _a.connection, invoker = _a.invoker, id = _a.id, recipientId = _a.recipientId, _b = _a.cluster, cluster = _b === void 0 ? types_1.Cluster.Mainnet : _b;
303
- return __awaiter(this, void 0, void 0, function () {
304
- var program, stream, newRecipient, escrow, mint, newRecipientTokens, tx;
305
- return __generator(this, function (_c) {
306
- switch (_c.label) {
307
- case 0:
308
- program = initProgram(connection, invoker, cluster);
309
- stream = new web3_js_1.PublicKey(id);
310
- newRecipient = new web3_js_1.PublicKey(recipientId);
311
- return [4 /*yield*/, connection.getAccountInfo(stream)];
312
- case 1:
313
- escrow = _c.sent();
314
- if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
315
- throw new Error("Couldn't get account info");
316
- }
317
- mint = (0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data).mint;
318
- return [4 /*yield*/, ata(mint, newRecipient)];
319
- case 2:
320
- newRecipientTokens = _c.sent();
321
- return [4 /*yield*/, program.rpc.transferRecipient({
322
- accounts: {
323
- authority: invoker.publicKey,
324
- newRecipient: newRecipient,
325
- newRecipientTokens: newRecipientTokens,
326
- metadata: stream,
327
- mint: mint,
328
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
329
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
330
- associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
331
- systemProgram: anchor_1.web3.SystemProgram.programId,
332
- },
333
- })];
334
- case 3:
335
- tx = _c.sent();
336
- return [2 /*return*/, { tx: tx }];
337
- }
338
- });
339
- });
340
- };
341
- /**
342
- * Tops up stream account deposited amount.
343
- * @param {TopupStreamParams} data
344
- * @param {Connection} data.connection - A connection to the cluster.
345
- * @param {Wallet} data.invoker - Wallet signing the transaction. It's address should match current stream sender or transaction will fail.
346
- * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be topped up.
347
- * @param {BN} data.amount - Specified amount (in the smallest units) to topup (increases deposited amount).
348
- * @param {ClusterExtended} [data.cluster = Cluster.Mainnet] - Cluster: devnet, mainnet-beta, testnet or local (optional).
349
- */
350
- Stream.topup = function (_a) {
351
- var connection = _a.connection, invoker = _a.invoker, id = _a.id, amount = _a.amount, _b = _a.cluster, cluster = _b === void 0 ? types_1.Cluster.Mainnet : _b;
352
- return __awaiter(this, void 0, void 0, function () {
353
- var program, streamPublicKey, escrow, _c, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, tx;
354
- return __generator(this, function (_d) {
355
- switch (_d.label) {
356
- case 0:
357
- program = initProgram(connection, invoker, cluster);
358
- streamPublicKey = new web3_js_1.PublicKey(id);
359
- return [4 /*yield*/, connection.getAccountInfo(streamPublicKey)];
360
- case 1:
361
- escrow = _d.sent();
362
- if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
363
- throw new Error("Couldn't get account info");
364
- }
365
- _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;
366
- return [4 /*yield*/, ata(mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
367
- case 2:
368
- streamflowTreasuryTokens = _d.sent();
369
- return [4 /*yield*/, ata(mint, partner)];
370
- case 3:
371
- partnerTokens = _d.sent();
372
- return [4 /*yield*/, program.rpc.topup(amount, {
373
- accounts: {
374
- sender: invoker.publicKey,
375
- senderTokens: senderTokens,
376
- metadata: streamPublicKey,
377
- escrowTokens: escrowTokens,
378
- streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
379
- streamflowTreasuryTokens: streamflowTreasuryTokens,
380
- partner: partner,
381
- partnerTokens: partnerTokens,
382
- mint: mint,
383
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
384
- withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
385
- systemProgram: anchor_1.web3.SystemProgram.programId,
386
- },
387
- })];
388
- case 4:
389
- tx = _d.sent();
390
- return [2 /*return*/, { tx: tx }];
391
- }
392
- });
393
- });
394
- };
395
- /**
396
- * Fetch stream data by its id (address).
397
- * @param {GetStreamParams} data
398
- * @param {Connection} data.connection - A connection to the cluster.
399
- * @param {string} data.id - Identifier of a stream that is fetched.
400
- */
401
- Stream.getOne = function (_a) {
402
- var connection = _a.connection, id = _a.id;
403
- return __awaiter(this, void 0, void 0, function () {
404
- var escrow;
405
- return __generator(this, function (_b) {
406
- switch (_b.label) {
407
- case 0: return [4 /*yield*/, connection.getAccountInfo(new web3_js_1.PublicKey(id), constants_1.TX_FINALITY_CONFIRMED)];
408
- case 1:
409
- escrow = _b.sent();
410
- if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
411
- throw new Error("Couldn't get account info.");
412
- }
413
- return [2 /*return*/, new types_1.Contract((0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data))];
414
- }
415
- });
416
- });
417
- };
418
- /**
419
- * Fetch streams/contracts by providing direction.
420
- * Streams are sorted by start time in ascending order.
421
- * @param {GetStreamsParams} data
422
- * @param {Connection} data.connection - A connection to the cluster.
423
- * @param {PublicKey} data.wallet - PublicKey of the wallet for which the streams/contracts are fetched.
424
- * @param {StreamType} [data.type = StreamType.All] - It can be one of: stream, vesting, all.
425
- * @param {StreamDirection} [data.direction = StreamDirection.All] - It can be one of: incoming, outgoing, all.
426
- * @param {ClusterExtended} [data.cluster = Cluster.Mainnet] - Cluster: devnet, mainnet-beta, testnet or local (optional).
427
- */
428
- Stream.get = function (_a) {
429
- var connection = _a.connection, 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, _d = _a.cluster, cluster = _d === void 0 ? types_1.Cluster.Mainnet : _d;
430
- return __awaiter(this, void 0, void 0, function () {
431
- var accounts, outgoingAccounts, incomingAccounts, offset, streams, sortedStreams;
432
- return __generator(this, function (_e) {
433
- switch (_e.label) {
434
- case 0:
435
- accounts = [];
436
- if (!(direction === "all")) return [3 /*break*/, 3];
437
- return [4 /*yield*/, getProgramAccounts(connection, wallet, constants_1.STREAM_STRUCT_OFFSET_SENDER, cluster)];
438
- case 1:
439
- outgoingAccounts = _e.sent();
440
- return [4 /*yield*/, getProgramAccounts(connection, wallet, constants_1.STREAM_STRUCT_OFFSET_RECIPIENT, cluster)];
441
- case 2:
442
- incomingAccounts = _e.sent();
443
- accounts = __spreadArray(__spreadArray([], __read(outgoingAccounts), false), __read(incomingAccounts), false);
444
- return [3 /*break*/, 5];
445
- case 3:
446
- offset = direction === "outgoing"
447
- ? constants_1.STREAM_STRUCT_OFFSET_SENDER
448
- : constants_1.STREAM_STRUCT_OFFSET_RECIPIENT;
449
- return [4 /*yield*/, getProgramAccounts(connection, wallet, offset, cluster)];
450
- case 4:
451
- accounts = _e.sent();
452
- _e.label = 5;
453
- case 5:
454
- streams = {};
455
- accounts.forEach(function (account) {
456
- var _a;
457
- var decoded = new types_1.Contract((0, utils_1.decodeStream)(account.account.data));
458
- streams = __assign(__assign({}, streams), (_a = {}, _a[account.pubkey.toBase58()] = decoded, _a));
459
- });
460
- sortedStreams = Object.entries(streams).sort(function (_a, _b) {
461
- var _c = __read(_a, 2), stream1 = _c[1];
462
- var _d = __read(_b, 2), stream2 = _d[1];
463
- return stream2.startTime - stream1.startTime;
464
- });
465
- if (type === "all")
466
- return [2 /*return*/, sortedStreams];
467
- return [2 /*return*/, type === "stream"
468
- ? sortedStreams.filter(function (stream) { return stream[1].canTopup; })
469
- : sortedStreams.filter(function (stream) { return !stream[1].canTopup; })];
470
- }
471
- });
472
- });
473
- };
474
- return Stream;
475
- }());
476
- exports.default = Stream;
477
- function getProgramAccounts(connection, wallet, offset, cluster) {
478
- if (cluster === void 0) { cluster = types_1.Cluster.Mainnet; }
479
- return __awaiter(this, void 0, void 0, function () {
480
- return __generator(this, function (_a) {
481
- return [2 /*return*/, connection === null || connection === void 0 ? void 0 : connection.getProgramAccounts(new web3_js_1.PublicKey(constants_1.PROGRAM_ID[cluster]), {
482
- filters: [
483
- {
484
- memcmp: {
485
- offset: offset,
486
- bytes: wallet.toBase58(),
487
- },
488
- },
489
- ],
490
- })];
491
- });
492
- });
493
- }
494
- function ata(mint, account) {
495
- return __awaiter(this, void 0, void 0, function () {
496
- return __generator(this, function (_a) {
497
- switch (_a.label) {
498
- 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)];
499
- case 1: return [2 /*return*/, _a.sent()];
500
- }
501
- });
502
- });
503
- }
@@ -1,145 +0,0 @@
1
- import { Connection, Commitment, ConnectionConfig } from "@solana/web3.js";
2
- import { Stream as StreamData, CreateParams, CreateMultiParams, WithdrawParams, TopupParams, CancelParams, TransferParams, ClusterExtended, GetAllParams, CreateResponse, CreateMultiResponse, TxResponse } from "./types";
3
- export default class StreamClient {
4
- private connection;
5
- private cluster;
6
- private programId;
7
- private commitment;
8
- /**
9
- * Create Stream instance
10
- */
11
- constructor(clusterUrl: string, cluster?: ClusterExtended, commitment?: Commitment | ConnectionConfig, programId?: string);
12
- getConnection(): Connection;
13
- getProgramId(): string;
14
- /**
15
- * Creates a new stream/vesting contract.
16
- * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
17
- * @param {CreateParams} data
18
- * @param {WalletAdapter | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
19
- * @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
20
- * @param {string} data.mint - SPL Token mint.
21
- * @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
22
- * @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
23
- * @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
24
- * @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
25
- * @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
26
- * @param {BN} data.amountPerPeriod - Amount unlocked per each period.
27
- * @param {string} data.name - Stream name/subject.
28
- * @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
29
- * @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
30
- * @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
31
- * @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
32
- * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
33
- * @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
34
- * @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.
35
- * @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
36
- * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
37
- */
38
- create({ sender, recipient, mint, start, depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, isNative, }: CreateParams): Promise<CreateResponse>;
39
- /**
40
- * Creates a new stream/vesting contract using unchecked instruction.
41
- *
42
- * Unchecked instruction differes from the regular in:
43
- * - does not check for initialized associated token account (wallets with no control over their ATA should not be used
44
- * as sender/recipient/partner or there are risks of funds being locked in the contract)
45
- * - initialized contract PDA off chain
46
- *
47
- * If you are not sure if you should use create or create_unchecked, go for create to be safer.
48
- *
49
- * @param {CreateParams} data
50
- * @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
51
- * @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
52
- * @param {string} data.mint - SPL Token mint.
53
- * @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
54
- * @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
55
- * @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
56
- * @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
57
- * @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
58
- * @param {BN} data.amountPerPeriod - Amount unlocked per each period.
59
- * @param {string} data.name - Stream name/subject.
60
- * @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
61
- * @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
62
- * @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
63
- * @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
64
- * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
65
- * @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
66
- * @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.
67
- * @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
68
- * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
69
- */
70
- createUnchecked({ sender, recipient, mint, start, depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, isNative, }: CreateParams): Promise<CreateResponse>;
71
- /**
72
- * Creates a new stream/vesting contract.
73
- * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
74
- * @param {CreateMultiParams} data
75
- * @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
76
- * @param {MultiRecipient[]} data.recipientsData
77
- * @param {string} data.mint - SPL Token mint.
78
- * @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
79
- * @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
80
- * @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
81
- * @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
82
- * @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
83
- * @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
84
- * @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
85
- * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
86
- * @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
87
- * @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.
88
- * @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
89
- * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
90
- */
91
- createMultiple(data: CreateMultiParams): Promise<CreateMultiResponse>;
92
- /**
93
- * Attempts withdrawal from the specified stream.
94
- * @param {WithdrawParams} data
95
- * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (recipient) or transaction will fail.
96
- * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be withdrawn from.
97
- * @param {BN} data.amount - Requested amount (in the smallest units) to withdraw (while streaming). If stream is completed, the whole amount will be withdrawn.
98
- */
99
- withdraw({ invoker, id, amount, }: WithdrawParams): Promise<TxResponse>;
100
- /**
101
- * Attempts canceling the specified stream.
102
- * @param {CancelParams} data
103
- * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
104
- * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be canceled.
105
- */
106
- cancel({ invoker, id }: CancelParams): Promise<TxResponse>;
107
- /**
108
- * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
109
- * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
110
- * @param {TransferParams} data
111
- * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
112
- * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be transferred.
113
- * @param {string} data.recipientId - Address of a new recipient.
114
- */
115
- transfer({ invoker, id, recipientId, }: TransferParams): Promise<TxResponse>;
116
- /**
117
- * Tops up stream account deposited amount.
118
- * @param {TopupParams} data
119
- * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match current stream sender or transaction will fail.
120
- * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be topped up.
121
- * @param {BN} data.amount - Specified amount (in the smallest units) to topup (increases deposited amount).
122
- */
123
- topup({ invoker, id, amount, isNative, }: TopupParams): Promise<TxResponse>;
124
- /**
125
- * Fetch stream data by its id (address).
126
- * @param {string} id - Identifier of a stream that is fetched.
127
- */
128
- getOne(id: string): Promise<StreamData>;
129
- /**
130
- * Fetch streams/contracts by providing direction.
131
- * Streams are sorted by start time in ascending order.
132
- * @param {GetAllParams} data
133
- * @param {PublicKey} data.wallet - PublicKey of the wallet for which the streams/contracts are fetched.
134
- * @param {StreamType} [data.type = StreamType.All] - It can be one of: stream, vesting, all.
135
- * @param {StreamDirection} [data.direction = StreamDirection.All] - It can be one of: incoming, outgoing, all.
136
- */
137
- get({ wallet, type, direction, }: GetAllParams): Promise<[string, StreamData][]>;
138
- private sign;
139
- /**
140
- * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
141
- * @param {MultiRecipient} recipient - Wallet sending stream to
142
- * @param {CreateMultiParams} streamParams - Parameters of stream user wants to create.
143
- */
144
- private prepareStreamTransaction;
145
- }