@streamflow/stream 2.0.2-beta.24

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.
package/README.md ADDED
@@ -0,0 +1,203 @@
1
+ **Important: Security audit is underway.**
2
+
3
+ Docs: https://streamflow.finance/js-sdk/
4
+ # Streamflow
5
+ Streamflow is a token distribution platform powered by a streaming payments' protocol.
6
+
7
+ Streamflow program ID (devnet) => `HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ`
8
+ <br>
9
+ Streamflow program ID (mainnet) => `strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m`
10
+
11
+ There are several ways to use Streamflow protocol:
12
+
13
+ - **(preferred) Application with UI** => [app.streamflow.finance](https://app.streamflow.finance)
14
+ - **JS SDK** (this repo) => [NPM package](https://www.npmjs.com/package/@streamflow/stream/v/2.0.0)
15
+ - **Rust SDK** for integration within Solana programs => [here](https://github.com/streamflow-finance/rust-sdk)
16
+
17
+ [**Streamflow Community** (free and open source, with limited features) is available here.](https://github.com/streamflow-finance/js-sdk/tree/community)
18
+
19
+ ## JS SDK to interact with Streamflow protocol.
20
+ This package allows you to `create`, `withdraw`, `cancel`, `topup` and `transfer` SPL token stream.
21
+
22
+ You can also `getOne` stream and `get` multiple streams.
23
+
24
+ ### Install the Streamflow JS SDK
25
+
26
+ `npm i @streamflow/stream @solana/web3.js @project-serum/anchor`
27
+
28
+
29
+ >_Anchor is needed for the `Wallet` type. We plan on removing this dependency in upcoming releases._
30
+
31
+ `bn.js` library is used for handling big numbers.
32
+
33
+ ```javascript
34
+ import { Connection } from "@solana/web3.js";
35
+ import { Wallet } from "@project-serum/anchor/src/provider";
36
+ import BN from "bn.js";
37
+ ```
38
+
39
+ ## Import SDK
40
+
41
+ Most common imports:
42
+
43
+ ```javascript
44
+ import Stream, {
45
+ Stream,
46
+ CreateStreamParams,
47
+ WithdrawStreamParams,
48
+ TransferStreamParams,
49
+ TopupStreamParams,
50
+ CancelStreamParams,
51
+ GetStreamParams,
52
+ GetStreamsParams,
53
+ StreamDirection,
54
+ StreamType,
55
+ Cluster,
56
+ TransactionResponse,
57
+ CreateStreamResponse,
58
+ } from "@streamflow/stream";
59
+ ```
60
+ _Check the SDK for other types and utility functions._
61
+
62
+ ### Create stream
63
+
64
+ ```javascript
65
+ const createStreamParams = {
66
+ connection: connection, // Connection to the cluster.
67
+ sender: wallet, // Wallet signing the transaction, creating and sending the stream.
68
+ recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Solana recipient address.
69
+ mint: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // SPL Token mint.
70
+ start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
71
+ depositedAmount: new BN(1000000000000), // Deposited amount of tokens (in the smallest units).
72
+ period: 1, // Time step (period) in seconds per which the unlocking occurs.
73
+ cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds.
74
+ cliffAmount: new BN(100000000000), // Amount unlocked at the "cliff" timestamp.
75
+ amountPerPeriod: new BN(5000000000), // Release rate: how many tokens are unlocked per each period.
76
+ name: "Transfer to Jane Doe.", // The stream name/subject.
77
+ canTopup: false, // setting to FALSE will effectively create a vesting contract.
78
+ cancelableBySender: true, // Whether or not sender can cancel the stream.
79
+ cancelableByRecipient: false, // Whether or not recipient can cancel the stream.
80
+ transferableBySender: true, // Whether or not sender can transfer the stream.
81
+ transferableByRecipient: false, // Whether or not recipient can transfer the stream.
82
+ automaticWithdrawal: false, // Whether or not a 3rd party can initiate withdraw in the name of recipient (currently not used, set it to FALSE).
83
+ partner: null, // (optional) Partner's wallet address (string | null).
84
+ cluster: Cluster.Mainnet, // (optional) Cluster (default is Cluster.Mainnet).
85
+ };
86
+
87
+ try {
88
+ const { tx, id } = await Stream.create(createStreamParams);
89
+ } catch (exception) {
90
+ // handle exception
91
+ }
92
+ ```
93
+
94
+ ## Withdraw from stream
95
+
96
+ ```javascript
97
+ const withdrawStreamParams = {
98
+ connection: connection, // Connection to the cluster.
99
+ invoker: wallet, // Wallet signing the transaction.
100
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be withdrawn from.
101
+ amount: new BN(100000000000), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
102
+ cluster: Cluster.Mainnet, // Cluster (optional, default is Cluster.Mainnet).
103
+ };
104
+
105
+ try {
106
+ const { tx } = await Stream.withdraw(withdrawStreamParams);
107
+ } catch (exception) {
108
+ // handle exception
109
+ }
110
+ ```
111
+
112
+ ## Topup stream
113
+
114
+ ```javascript
115
+ const topupStreamParams = {
116
+ connection: connection, // Connection to the cluster.
117
+ invoker: wallet, // Wallet signing the transaction.
118
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be topped up.
119
+ amount: new BN(100000000000), // Specified amount to topup (increases deposited amount).
120
+ cluster: Cluster.Mainnet, // Cluster (optional, default is Cluster.Mainnet).
121
+ };
122
+
123
+ try {
124
+ const { tx } = await Stream.topup(topupStreamParams);
125
+ } catch (exception) {
126
+ // handle exception
127
+ }
128
+ ```
129
+
130
+ ## Transfer stream to another recipient
131
+
132
+ ```javascript
133
+ const data = {
134
+ connection: connection, // Connection to the cluster.
135
+ invoker: wallet, // Wallet signing the transaction.
136
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
137
+ recipientId: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99", // Identifier of a stream to be transferred.
138
+ cluster: Cluster.Mainnet, // Cluster (optional, default is Cluster.Mainnet).
139
+ };
140
+
141
+ try {
142
+ const { tx } = await Stream.transfer(data);
143
+ } catch (exception) {
144
+ // handle exception
145
+ }
146
+ ```
147
+
148
+ ## Cancel stream
149
+
150
+ ```javascript
151
+ const cancelStreamParams = {
152
+ connection: connection, // Connection to the cluster.
153
+ invoker: wallet, // Wallet signing the transaction.
154
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be canceled.
155
+ cluster: Cluster.Mainnet, // Cluster (optional, default is Cluster.Mainnet).
156
+ };
157
+
158
+ try {
159
+ const { tx } = await Stream.cancel(cancelStreamParams);
160
+ } catch (exception) {
161
+ // handle exception
162
+ }
163
+ ```
164
+
165
+ ## Get stream by ID
166
+
167
+ ```javascript
168
+ try {
169
+ const stream = await Stream.getOne({
170
+ connection: connection, // Connection to the cluster.
171
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream that is fetched.
172
+ });
173
+ } catch (exception) {
174
+ // handle exception
175
+ }
176
+ ```
177
+
178
+ ## Get streams for a specific wallet address
179
+
180
+ ```javascript
181
+ try {
182
+ const streams = Stream.get({
183
+ connection: connection, // Connection to the cluster.
184
+ wallet: wallet, // Wallet signing the transaction.
185
+ type: StreamType.All, // (optional) Type, default is StreamType.All
186
+ direction: StreamDirection.All, // (optional) Direction, default is StreamDirection.All)
187
+ cluster: Cluster.Mainnet, // (optional) Cluster, default is Cluster.Mainnet).
188
+ });
189
+ } catch (exception) {
190
+ // handle exception
191
+ }
192
+ ```
193
+
194
+ ### Additional notes
195
+
196
+ #### All BN amounts are denominated in their smallest units.
197
+
198
+ E.g, if the amount is 1 SOL than this amount in lamports is 1000 \* 10^9 = 1_000_000_000.
199
+ And `new BN(1_000_000_000)` is used.
200
+
201
+ Use `getBN` and `getNumberFromBN` utility functions for conversions between `BN` and `Number` types.
202
+
203
+ WAGMI.
@@ -0,0 +1,14 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ export declare const TX_FINALITY_CONFIRMED = "confirmed";
3
+ export declare const STREAM_STRUCT_OFFSET_SENDER = 49;
4
+ export declare const STREAM_STRUCT_OFFSET_RECIPIENT = 113;
5
+ export declare const PROGRAM_ID: {
6
+ devnet: string;
7
+ "mainnet-beta": string;
8
+ testnet: string;
9
+ local: string;
10
+ };
11
+ export declare const STREAMFLOW_PROGRAM_ID = "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m";
12
+ export declare const STREAMFLOW_DEVNET_PROGRAM_ID = "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ";
13
+ export declare const STREAMFLOW_TREASURY_PUBLIC_KEY: PublicKey;
14
+ export declare const WITHDRAWOR_PUBLIC_KEY: PublicKey;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.STREAMFLOW_DEVNET_PROGRAM_ID = exports.STREAMFLOW_PROGRAM_ID = exports.PROGRAM_ID = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
5
+ var web3_js_1 = require("@solana/web3.js");
6
+ var types_1 = require("./types");
7
+ exports.TX_FINALITY_CONFIRMED = "confirmed";
8
+ exports.STREAM_STRUCT_OFFSET_SENDER = 49;
9
+ exports.STREAM_STRUCT_OFFSET_RECIPIENT = 113;
10
+ exports.PROGRAM_ID = (_a = {},
11
+ _a[types_1.Cluster.Devnet] = "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
12
+ _a[types_1.Cluster.Mainnet] = "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m",
13
+ _a[types_1.Cluster.Testnet] = "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
14
+ _a[types_1.LocalCluster.Local] = "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
15
+ _a);
16
+ exports.STREAMFLOW_PROGRAM_ID = "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m";
17
+ exports.STREAMFLOW_DEVNET_PROGRAM_ID = "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ";
18
+ exports.STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js_1.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
19
+ exports.WITHDRAWOR_PUBLIC_KEY = new web3_js_1.PublicKey("wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u");
package/dist/idl.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ declare const _default: {
2
+ version: string;
3
+ name: string;
4
+ instructions: {
5
+ name: string;
6
+ accounts: {
7
+ name: string;
8
+ isMut: boolean;
9
+ isSigner: boolean;
10
+ }[];
11
+ args: ({
12
+ name: string;
13
+ type: string;
14
+ } | {
15
+ name: string;
16
+ type: {
17
+ array: (string | number)[];
18
+ };
19
+ })[];
20
+ }[];
21
+ };
22
+ export default _default;
package/dist/idl.js ADDED
@@ -0,0 +1,422 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ version: "0.1.0",
5
+ name: "timelock",
6
+ instructions: [
7
+ {
8
+ name: "create",
9
+ accounts: [
10
+ {
11
+ name: "sender",
12
+ isMut: true,
13
+ isSigner: true,
14
+ },
15
+ {
16
+ name: "senderTokens",
17
+ isMut: true,
18
+ isSigner: false,
19
+ },
20
+ {
21
+ name: "recipient",
22
+ isMut: true,
23
+ isSigner: false,
24
+ },
25
+ {
26
+ name: "metadata",
27
+ isMut: true,
28
+ isSigner: true,
29
+ },
30
+ {
31
+ name: "escrowTokens",
32
+ isMut: true,
33
+ isSigner: false,
34
+ },
35
+ {
36
+ name: "recipientTokens",
37
+ isMut: true,
38
+ isSigner: false,
39
+ },
40
+ {
41
+ name: "streamflowTreasury",
42
+ isMut: true,
43
+ isSigner: false,
44
+ },
45
+ {
46
+ name: "streamflowTreasuryTokens",
47
+ isMut: true,
48
+ isSigner: false,
49
+ },
50
+ {
51
+ name: "withdrawor",
52
+ isMut: true,
53
+ isSigner: false,
54
+ },
55
+ {
56
+ name: "partner",
57
+ isMut: true,
58
+ isSigner: false,
59
+ },
60
+ {
61
+ name: "partnerTokens",
62
+ isMut: true,
63
+ isSigner: false,
64
+ },
65
+ {
66
+ name: "mint",
67
+ isMut: false,
68
+ isSigner: false,
69
+ },
70
+ {
71
+ name: "feeOracle",
72
+ isMut: false,
73
+ isSigner: false,
74
+ },
75
+ {
76
+ name: "rent",
77
+ isMut: false,
78
+ isSigner: false,
79
+ },
80
+ {
81
+ name: "timelockProgram",
82
+ isMut: false,
83
+ isSigner: false,
84
+ },
85
+ {
86
+ name: "tokenProgram",
87
+ isMut: false,
88
+ isSigner: false,
89
+ },
90
+ {
91
+ name: "associatedTokenProgram",
92
+ isMut: false,
93
+ isSigner: false,
94
+ },
95
+ {
96
+ name: "systemProgram",
97
+ isMut: false,
98
+ isSigner: false,
99
+ },
100
+ ],
101
+ args: [
102
+ {
103
+ name: "startTime",
104
+ type: "u64",
105
+ },
106
+ {
107
+ name: "netAmountDeposited",
108
+ type: "u64",
109
+ },
110
+ {
111
+ name: "period",
112
+ type: "u64",
113
+ },
114
+ {
115
+ name: "amountPerPeriod",
116
+ type: "u64",
117
+ },
118
+ {
119
+ name: "cliff",
120
+ type: "u64",
121
+ },
122
+ {
123
+ name: "cliffAmount",
124
+ type: "u64",
125
+ },
126
+ {
127
+ name: "cancelableBySender",
128
+ type: "bool",
129
+ },
130
+ {
131
+ name: "cancelableByRecipient",
132
+ type: "bool",
133
+ },
134
+ {
135
+ name: "automaticWithdrawal",
136
+ type: "bool",
137
+ },
138
+ {
139
+ name: "transferableBySender",
140
+ type: "bool",
141
+ },
142
+ {
143
+ name: "transferableByRecipient",
144
+ type: "bool",
145
+ },
146
+ {
147
+ name: "canTopup",
148
+ type: "bool",
149
+ },
150
+ {
151
+ name: "streamName",
152
+ type: {
153
+ array: ["u8", 64],
154
+ },
155
+ },
156
+ {
157
+ name: "withdrawFrequency",
158
+ type: "u64",
159
+ },
160
+ ],
161
+ },
162
+ {
163
+ name: "withdraw",
164
+ accounts: [
165
+ {
166
+ name: "authority",
167
+ isMut: false,
168
+ isSigner: true,
169
+ },
170
+ {
171
+ name: "recipient",
172
+ isMut: true,
173
+ isSigner: false,
174
+ },
175
+ {
176
+ name: "recipientTokens",
177
+ isMut: true,
178
+ isSigner: false,
179
+ },
180
+ {
181
+ name: "metadata",
182
+ isMut: true,
183
+ isSigner: false,
184
+ },
185
+ {
186
+ name: "escrowTokens",
187
+ isMut: true,
188
+ isSigner: false,
189
+ },
190
+ {
191
+ name: "streamflowTreasury",
192
+ isMut: true,
193
+ isSigner: false,
194
+ },
195
+ {
196
+ name: "streamflowTreasuryTokens",
197
+ isMut: true,
198
+ isSigner: false,
199
+ },
200
+ {
201
+ name: "partner",
202
+ isMut: true,
203
+ isSigner: false,
204
+ },
205
+ {
206
+ name: "partnerTokens",
207
+ isMut: true,
208
+ isSigner: false,
209
+ },
210
+ {
211
+ name: "mint",
212
+ isMut: false,
213
+ isSigner: false,
214
+ },
215
+ {
216
+ name: "tokenProgram",
217
+ isMut: false,
218
+ isSigner: false,
219
+ },
220
+ ],
221
+ args: [
222
+ {
223
+ name: "amount",
224
+ type: "u64",
225
+ },
226
+ ],
227
+ },
228
+ {
229
+ name: "cancel",
230
+ accounts: [
231
+ {
232
+ name: "authority",
233
+ isMut: false,
234
+ isSigner: true,
235
+ },
236
+ {
237
+ name: "sender",
238
+ isMut: true,
239
+ isSigner: false,
240
+ },
241
+ {
242
+ name: "senderTokens",
243
+ isMut: true,
244
+ isSigner: false,
245
+ },
246
+ {
247
+ name: "recipient",
248
+ isMut: true,
249
+ isSigner: false,
250
+ },
251
+ {
252
+ name: "recipientTokens",
253
+ isMut: true,
254
+ isSigner: false,
255
+ },
256
+ {
257
+ name: "metadata",
258
+ isMut: true,
259
+ isSigner: false,
260
+ },
261
+ {
262
+ name: "escrowTokens",
263
+ isMut: true,
264
+ isSigner: false,
265
+ },
266
+ {
267
+ name: "streamflowTreasury",
268
+ isMut: true,
269
+ isSigner: false,
270
+ },
271
+ {
272
+ name: "streamflowTreasuryTokens",
273
+ isMut: true,
274
+ isSigner: false,
275
+ },
276
+ {
277
+ name: "partner",
278
+ isMut: true,
279
+ isSigner: false,
280
+ },
281
+ {
282
+ name: "partnerTokens",
283
+ isMut: true,
284
+ isSigner: false,
285
+ },
286
+ {
287
+ name: "mint",
288
+ isMut: false,
289
+ isSigner: false,
290
+ },
291
+ {
292
+ name: "tokenProgram",
293
+ isMut: false,
294
+ isSigner: false,
295
+ },
296
+ ],
297
+ args: [],
298
+ },
299
+ {
300
+ name: "transferRecipient",
301
+ accounts: [
302
+ {
303
+ name: "authority",
304
+ isMut: true,
305
+ isSigner: true,
306
+ },
307
+ {
308
+ name: "newRecipient",
309
+ isMut: true,
310
+ isSigner: false,
311
+ },
312
+ {
313
+ name: "newRecipientTokens",
314
+ isMut: true,
315
+ isSigner: false,
316
+ },
317
+ {
318
+ name: "metadata",
319
+ isMut: true,
320
+ isSigner: false,
321
+ },
322
+ {
323
+ name: "mint",
324
+ isMut: false,
325
+ isSigner: false,
326
+ },
327
+ {
328
+ name: "rent",
329
+ isMut: false,
330
+ isSigner: false,
331
+ },
332
+ {
333
+ name: "tokenProgram",
334
+ isMut: false,
335
+ isSigner: false,
336
+ },
337
+ {
338
+ name: "associatedTokenProgram",
339
+ isMut: false,
340
+ isSigner: false,
341
+ },
342
+ {
343
+ name: "systemProgram",
344
+ isMut: false,
345
+ isSigner: false,
346
+ },
347
+ ],
348
+ args: [],
349
+ },
350
+ {
351
+ name: "topup",
352
+ accounts: [
353
+ {
354
+ name: "sender",
355
+ isMut: true,
356
+ isSigner: true,
357
+ },
358
+ {
359
+ name: "senderTokens",
360
+ isMut: true,
361
+ isSigner: false,
362
+ },
363
+ {
364
+ name: "metadata",
365
+ isMut: true,
366
+ isSigner: false,
367
+ },
368
+ {
369
+ name: "escrowTokens",
370
+ isMut: true,
371
+ isSigner: false,
372
+ },
373
+ {
374
+ name: "streamflowTreasury",
375
+ isMut: true,
376
+ isSigner: false,
377
+ },
378
+ {
379
+ name: "streamflowTreasuryTokens",
380
+ isMut: true,
381
+ isSigner: false,
382
+ },
383
+ {
384
+ name: "withdrawor",
385
+ isMut: true,
386
+ isSigner: false,
387
+ },
388
+ {
389
+ name: "partner",
390
+ isMut: true,
391
+ isSigner: false,
392
+ },
393
+ {
394
+ name: "partnerTokens",
395
+ isMut: true,
396
+ isSigner: false,
397
+ },
398
+ {
399
+ name: "mint",
400
+ isMut: false,
401
+ isSigner: false,
402
+ },
403
+ {
404
+ name: "tokenProgram",
405
+ isMut: false,
406
+ isSigner: false,
407
+ },
408
+ {
409
+ name: "systemProgram",
410
+ isMut: false,
411
+ isSigner: false,
412
+ },
413
+ ],
414
+ args: [
415
+ {
416
+ name: "amount",
417
+ type: "u64",
418
+ },
419
+ ],
420
+ },
421
+ ],
422
+ };
@@ -0,0 +1,5 @@
1
+ export { default } from "./sdk";
2
+ export * from "./utils";
3
+ export * from "./types";
4
+ export * from "./instructions";
5
+ export { u64 } from "@solana/spl-token";