@streamflow/stream 4.1.0-beta.9 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,6 @@
1
- Docs: https://streamflow.finance/js-sdk/
2
-
3
1
  # Streamflow
4
2
 
5
- Streamflow is a token distribution platform powered by a streaming payments' protocol.
3
+ Streamflow is a token vesting and streaming payments platform.
6
4
 
7
5
  There are several ways to use **Streamflow**:
8
6
 
@@ -12,12 +10,12 @@ There are several ways to use **Streamflow**:
12
10
 
13
11
  **Security audit passed ✅**
14
12
 
15
- Protocol audit available [here](https://github.com/streamflow-finance/rust-sdk/blob/main/protocol_audit.pdf).
13
+ Protocol audits available [here](https://www.notion.so/streamflow/Streamflow-Security-Audits-3250070c0b3a4a0690385d96316d645c).
16
14
  Partner oracle audit available here [here](https://github.com/streamflow-finance/rust-sdk/blob/main/partner_oracle_audit.pdf).
17
15
 
18
16
  ## JS SDK to interact with Streamflow protocol.
19
17
 
20
- This package allows you to `create`, `createMultiple`, `withdraw`, `cancel`, `topup` and `transfer` SPL token stream.
18
+ This package allows you to `create`, `createMultiple`, `withdraw`, `cancel`, `topup`, `transfer`, `update` a token stream.
21
19
 
22
20
  You can also `getOne` stream and `get` multiple streams.
23
21
 
@@ -37,54 +35,103 @@ or
37
35
  Most common imports:
38
36
 
39
37
  ```javascript
40
- import {
41
- GenericStreamClient,
42
- StreamflowSolana,
43
- StreamflowAptos,
44
- Types,
45
- getBN,
46
- getNumberFromBN,
47
- } from "@streamflow/stream";
38
+ import { BN } from "bn.js";
39
+ import { Types, GenericStreamClient, getBN, getNumberFromBN } from "@streamflow/stream";
48
40
  ```
49
41
 
50
42
  _Check the SDK for other types and utility functions._
51
43
 
52
44
  ## Create StreamClient instance
53
45
 
54
- Before creating and manipulating streams chain specific or generic StreamClient instance must be created.
55
- All streams functions are methods on this instance.
46
+ Before creating and manipulating streams chain specific or generic StreamClient instance must be created. All streams functions are methods on this instance.
56
47
 
57
48
  ### Solana
49
+
58
50
  ```javascript
59
- import { StreamflowSolana, Types } from "@streamflow/stream";
51
+ import {
52
+ StreamflowSolana,
53
+ Types,
54
+ } from "@streamflow/stream";
60
55
 
61
- const streamClient = new StreamflowSolana.SolanaStreamClient(
62
- "https://api.mainnet-beta.solana.com", // RPC cluster URL
63
- Types.ICluster.Mainnet, // (optional) (default: Mainnet) Solana cluster
64
- "confirmed", // (optional) (default: confirmed) Transaction commitment
56
+ const solanaClient = new StreamflowSolana.SolanaStreamClient(
57
+ "https://api.mainnet-beta.solana.com"
65
58
  );
66
59
  ```
60
+
67
61
  ### Aptos
62
+
68
63
  ```javascript
69
- import { StreamflowAptos, Types } from "@streamflow/stream";
64
+ import {
65
+ StreamflowAptos,
66
+ Types,
67
+ } from "@streamflow/stream";
70
68
 
71
- const StreamClient = new StreamflowAptos.AptosStreamClient(
72
- "https://fullnode.mainnet.aptoslabs.com/v1", // RPC cluster URL
73
- Types.ICluster.Mainnet, // (optional) (default: Mainnet) Aptos cluster
74
- "10000", // (optional) (default: "10000") maxGas for transactions
69
+ const aptosClient = new StreamflowAptos.AptosStreamClient(
70
+ "https://fullnode.mainnet.aptoslabs.com/v1"
75
71
  );
76
72
  ```
73
+
74
+ ### Ethereum
75
+
76
+ ```javascript
77
+ import {
78
+ StreamflowEVM,
79
+ Types,
80
+ } from "@streamflow/stream";
81
+
82
+ const ethereumClient = new StreamflowEVM.EvmStreamClient(
83
+ "YOUR_ETHEREUM_NODE_URL",
84
+ Types.IChain.Ethereum,
85
+ signer // will be sender in a stream and authority for all stream related transactions
86
+ );
87
+ ```
88
+
89
+
90
+ ### Polygon
91
+
92
+ ```javascript
93
+ import {
94
+ StreamflowEVM,
95
+ Types,
96
+ } from "@streamflow/stream";
97
+
98
+ const polygonClient = new StreamflowEVM.EvmStreamClient(
99
+ "YOUR_POLYGON_NODE_URL",
100
+ Types.IChain.Polygon,
101
+ signer // will be sender in a stream and authority for all stream related transactions
102
+ );
103
+ ```
104
+
105
+ ### BNB
106
+
107
+ ```javascript
108
+ import {
109
+ StreamflowEVM,
110
+ Types,
111
+ } from "@streamflow/stream";
112
+
113
+ const bnbClient = new StreamflowEVM.EvmStreamClient(
114
+ "https://bsc-dataseed1.binance.org/",
115
+ Types.IChain.BNB,
116
+ signer // will be sender in a stream and authority for all stream related transactions
117
+ );
118
+ ```
119
+
120
+
77
121
  ### Generic Stream Client
78
- Provides isomorphic interface to work with streams agnostic of chain.
122
+
123
+ GenericStreamClient provides isomorphic interface to work with streams agnostic of chain.
124
+
79
125
  ```javascript
80
126
  import { GenericStreamClient, Types } from "@streamflow/stream";
81
127
 
82
- const StreamClient = new StreamClient({
83
- chain: Types.IChain.Aptos, // Blockchain
84
- clusterUrl: "https://fullnode.mainnet.aptoslabs.com/v1", // RPC cluster URL
128
+ const client =
129
+ new GenericStreamClient<Types.IChain.Solana>({
130
+ chain: Types.IChain.Solana, // Blockchain
131
+ clusterUrl: "https://api.mainnet-beta.solana.com", // RPC cluster URL
85
132
  cluster: Types.ICluster.Mainnet, // (optional) (default: Mainnet)
86
133
  // ...rest chain specific params e.g. commitment for Solana
87
- });
134
+ });
88
135
  ```
89
136
 
90
137
  All the examples below will contain generic method options descriptions and chain specific params.
@@ -94,30 +141,28 @@ All the examples below will contain generic method options descriptions and chai
94
141
  ## Create stream
95
142
 
96
143
  ```javascript
97
- const createStreamParams = {
98
- tokenId: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // SPL token mint or Aptos Coin type
99
- recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Recipient address (base58 string for Solana)
100
- amount: getBN(1_000_000, 9), // Deposited amount of tokens (using smallest denomination).
101
- amountPerPeriod: getBN(1_000, 9), // Release rate: how many tokens are unlocked per each period.
102
- cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds.
103
- cliffAmount: getBN(100_000, 9),// Amount (smallest denomination) unlocked at the "cliff" timestamp.
104
- name: "Transfer to Jane Doe.", // The stream name or subject.
105
- period: 1, // Time step (period) in seconds per which the unlocking occurs.
106
- start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
107
- canTopup: false, // setting to FALSE will effectively create a vesting contract.
108
- cancelableBySender: true, // Wether or not sender can cancel the stream.
109
- cancelableByRecipient: false, // Wether or not recipient can cancel the stream.
110
- transferableBySender: true, // Wether or not sender can transfer the stream.
111
- transferableByRecipient: false, // Wether or not recipient can transfer the stream.
112
- automaticWithdrawal: true, // [optional] Wether or not a 3rd party (e.g. cron job, "cranker") can initiate a token withdraw/transfer.
113
- withdrawalFrequency: 10, // [optional] 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.
114
- canPause: false, // [optional] [WIP] Wether stream is Pausable
115
- canUpdateRate: fakse, // [optional] [WIP] Wether stream rate can be updated
144
+ const createStreamParams: Types.ICreateStreamData = {
145
+ recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Recipient address.
146
+ tokenId: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // Token mint address.
147
+ start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
148
+ amount: getBN(100, 9), // depositing 100 tokens with 9 decimals mint.
149
+ period: 1, // Time step (period) in seconds per which the unlocking occurs.
150
+ cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds.
151
+ cliffAmount: new BN(10), // Amount unlocked at the "cliff" timestamp.
152
+ amountPerPeriod: getBN(5, 9), // Release rate: how many tokens are unlocked per each period.
153
+ name: "Transfer to Jane Doe.", // The stream name or subject.
154
+ canTopup: false, // setting to FALSE will effectively create a vesting contract.
155
+ cancelableBySender: true, // Whether or not sender can cancel the stream.
156
+ cancelableByRecipient: false, // Whether or not recipient can cancel the stream.
157
+ transferableBySender: true, // Whether or not sender can transfer the stream.
158
+ transferableByRecipient: false, // Whether or not recipient can transfer the stream.
159
+ automaticWithdrawal: true, // Whether or not a 3rd party (e.g. cron job, "cranker") can initiate a token withdraw/transfer.
160
+ withdrawalFrequency: 10, // 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.
161
+ partner: null, // (optional) Partner's wallet address (string | null).
116
162
  };
117
163
 
118
164
  const solanaParams = {
119
165
  sender: wallet, // SignerWalletAdapter or Keypair of Sender account
120
- partner: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // [optional] Partner Solana address
121
166
  isNative: // [optional] [WILL CREATE A wSOL STREAM] Wether Stream or Vesting should be paid with Solana native token or not
122
167
  };
123
168
 
@@ -125,10 +170,12 @@ const aptosParams = {
125
170
  senderWallet: wallet, // AptosWalletAdapter Wallet of sender
126
171
  };
127
172
 
173
+ const ethereumParams = undefined;
174
+
128
175
  try {
129
- const { ixs, tx, metadata } = await solanaStreamClient.create(createStreamParams, solanaParams);
176
+ const { ixs, tx, metadata } = await client.create(createStreamParams, solanaParams); // second argument differ depending on a chain
130
177
  } catch (exception) {
131
- // handle exception
178
+ // handle exception
132
179
  }
133
180
  ```
134
181
 
@@ -136,35 +183,32 @@ try {
136
183
 
137
184
  ```javascript
138
185
  const recipients = [
139
- {
140
- recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Recipient address (base58 string for Solana)
141
- amount: getBN(1_000_000, 9), // Deposited amount of tokens (using smallest denomination).
142
- name: "Transfer to Jane Doe.", // The stream name or subject.
143
- cliffAmount: getBN(100_000, 9),// Amount (smallest denomination) unlocked at the "cliff" timestamp.
144
- amountPerPeriod: getBN(1_000, 9), // Release rate: how many tokens are unlocked per each period.
145
- },
146
- // ... Other Recipient options
186
+ {
187
+ recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Solana recipient address.
188
+ amount: getBN(100, 9), // depositing 100 tokens with 9 decimals mint.
189
+ name: "January Payroll", // The stream name/subject.
190
+ cliffAmount: getBN(10, 9), // amount released on cliff for this recipient
191
+ amountPerPeriod: getBN(1, 9), //amount released every specified period epoch
192
+ },
147
193
  ];
148
-
149
- const createMultiStreamsParams = {
150
- tokenId: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // SPL token mint or Aptos Coin type
151
- cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds.
152
- period: 1, // Time step (period) in seconds per which the unlocking occurs.
153
- start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
154
- canTopup: false, // setting to FALSE will effectively create a vesting contract.
155
- cancelableBySender: true, // Wether or not sender can cancel the stream.
156
- cancelableByRecipient: false, // Wether or not recipient can cancel the stream.
157
- transferableBySender: true, // Wether or not sender can transfer the stream.
158
- transferableByRecipient: false, // Wether or not recipient can transfer the stream.
159
- automaticWithdrawal: true, // [optional] Wether or not a 3rd party (e.g. cron job, "cranker") can initiate a token withdraw/transfer.
160
- withdrawalFrequency: 10, // [optional] 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.
161
- canPause: false, // [optional] [WIP] Wether stream is Pausable
162
- canUpdateRate: false, // [optional] [WIP] Wether stream rate can be updated
194
+ const createStreamParams: Types.ICreateMultipleStreamData = {
195
+ recipients: recipients, // Solana recipient address.
196
+ tokenId: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // SPL Token mint.
197
+ start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
198
+ period: 1, // Time step (period) in seconds per which the unlocking occurs.
199
+ cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds.
200
+ canTopup: false, // setting to FALSE will effectively create a vesting contract.
201
+ cancelableBySender: true, // Whether or not sender can cancel the stream.
202
+ cancelableByRecipient: false, // Whether or not recipient can cancel the stream.
203
+ transferableBySender: true, // Whether or not sender can transfer the stream.
204
+ transferableByRecipient: false, // Whether or not recipient can transfer the stream.
205
+ automaticWithdrawal: true, // Whether or not a 3rd party (e.g. cron job, "cranker") can initiate a token withdraw/transfer.
206
+ withdrawalFrequency: 10, // 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.
207
+ partner: null, // (optional) Partner's wallet address (string | null).
163
208
  };
164
209
 
165
210
  const solanaParams = {
166
211
  sender: wallet, // SignerWalletAdapter or Keypair of Sender account
167
- partner: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // [optional] Partner Solana address
168
212
  isNative: // [optional] [WILL CREATE A wSOL STREAM] Wether Stream or Vesting should be paid with Solana native token or not
169
213
  };
170
214
 
@@ -172,149 +216,219 @@ const aptosParams = {
172
216
  senderWallet: wallet, // AptosWalletAdapter Wallet of sender
173
217
  };
174
218
 
219
+ const ethereumParams = undefined;
220
+
175
221
  try {
176
- const { txs } = await StreamClient.createMultiple(createMultiStreamsParams, solanaParams);
222
+ const { txs } = await client.createMultiple(createMultiStreamsParams, solanaParams);
177
223
  } catch (exception) {
178
- // handle exception
224
+ // handle exception
225
+ }
226
+ ```
227
+
228
+ Please note that transaction fees for the scheduled transfers are paid upfront by the stream creator (sender).
229
+
230
+ ## Identifying created contracts (streams or vesting)
231
+
232
+ All Stream Clients return `Types.ICreateResult` object (`createdMultiple` returns an Array) that has the following structure
233
+
234
+ ```javascript
235
+ interface ICreateResult {
236
+ ixs: (TransactionInstruction | Types.TransactionPayload)[];
237
+ txId: string;
238
+ metadataId: MetadataId;
179
239
  }
180
240
  ```
181
241
 
242
+ `metadataId` is the id of the created stream.
243
+
182
244
  ## Withdraw from stream
183
245
 
184
246
  ```javascript
185
- const withdrawStreamParams = {
186
- id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be withdrawn from.
187
- amount: getBN(100000000000, 9), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
247
+ const withdrawStreamParams: Types.IWithdrawData = {
248
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be withdrawn from.
249
+ amount: getBN(100, 9), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
188
250
  };
189
251
 
190
252
  const solanaParams = {
191
- invoker: wallet, // Wallet/Keypair signing the transaction.
253
+ invoker: wallet, // SignerWalletAdapter or Keypair signing the transaction
192
254
  };
193
255
 
194
256
  const aptosParams = {
195
- senderWallet: wallet, // AptosWalletAdapter Wallet of sender
257
+ senderWallet: wallet, // AptosWalletAdapter Wallet of wallet signing the transaction
196
258
  tokenId: "0x1::aptos_coin::AptosCoin", // Aptos Coin type
197
259
  };
198
260
 
261
+ const ethereumParams = undefined;
199
262
 
200
263
  try {
201
- const { ixs, tx } = await StreamClient.withdraw(withdrawStreamParams, solanaParams);
264
+ const { ixs, tx } = await client.withdraw(withdrawStreamParams, solanaParams);
202
265
  } catch (exception) {
203
- // handle exception
266
+ // handle exception
204
267
  }
205
268
  ```
206
269
 
207
270
  ## Topup stream
208
271
 
209
272
  ```javascript
210
- const topupStreamParams = {
211
- invoker: wallet, // Wallet/Keypair signing the transaction.
212
- id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be topped up.
213
- amount: getBN(100000000000, 9), // Specified amount to topup (increases deposited amount).
273
+ const topupStreamParams: Types.ITopUpData = {
274
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be topped up.
275
+ amount: getBN(100, 9), // Specified amount to topup (increases deposited amount).
214
276
  };
215
277
 
216
278
  const solanaParams = {
217
- invoker: wallet, // Wallet/Keypair signing the transaction.
279
+ invoker: wallet, // SignerWalletAdapter or Keypair signing the transaction
218
280
  isNative: // [ONLY FOR wSOL STREAMS] [optional] Wether topup is with Native Solanas
219
281
  };
220
282
 
221
283
  const aptosParams = {
222
- senderWallet: wallet, // AptosWalletAdapter Wallet of sender
284
+ senderWallet: wallet, // AptosWalletAdapter Wallet of wallet signing the transaction
223
285
  tokenId: "0x1::aptos_coin::AptosCoin", // Aptos Coin type
224
286
  };
225
287
 
288
+ const ethereumParams = undefined;
289
+
226
290
  try {
227
- const { ixs, tx } = await StreamClient.topup(topupStreamParams, solanaParams);
291
+ const { ixs, tx } = await client.topup(topupStreamParams, solanaParams);
228
292
  } catch (exception) {
229
- // handle exception
293
+ // handle exception
230
294
  }
231
295
  ```
232
296
 
233
297
  ## Transfer stream to another recipient
234
298
 
235
299
  ```javascript
236
- const data = {
237
- id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",// Identifier of a stream to be transferred.
238
- recipientId: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99", // New Recipient address
300
+ const data: Types.ITransferData = {
301
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
302
+ newRecipient: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99", // Identifier of a stream to be transferred.
239
303
  };
240
304
 
241
305
  const solanaParams = {
242
- invoker: wallet, // Wallet/Keypair signing the transaction.
306
+ invoker: wallet, // SignerWalletAdapter or Keypair signing the transaction
243
307
  };
244
308
 
245
309
  const aptosParams = {
246
- senderWallet: wallet, // AptosWalletAdapter Wallet of sender
310
+ senderWallet: wallet, // AptosWalletAdapter Wallet of wallet signing the transaction
247
311
  tokenId: "0x1::aptos_coin::AptosCoin", // Aptos Coin type
248
312
  };
249
313
 
314
+ const ethereumParams = undefined;
250
315
 
251
316
  try {
252
- const { tx } = await StreamClient.transfer(data, solanaParams);
317
+ const { tx } = await client.transfer(data, solanaParams);
253
318
  } catch (exception) {
254
- // handle exception
319
+ // handle exception
255
320
  }
256
321
  ```
257
322
 
258
323
  ## Cancel stream
259
324
 
260
325
  ```javascript
261
- const cancelStreamParams = {
262
- id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be canceled.
326
+ const cancelStreamParams: Types.ICancelData = {
327
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be canceled.
263
328
  };
264
329
 
265
330
  const solanaParams = {
266
- invoker: wallet, // Wallet/Keypair signing the transaction.
331
+ invoker: wallet, // SignerWalletAdapter or Keypair signing the transaction
267
332
  };
268
333
 
269
334
  const aptosParams = {
270
- senderWallet: wallet, // AptosWalletAdapter Wallet of sender
335
+ senderWallet: wallet, // AptosWalletAdapter Wallet of wallet signing the transaction
271
336
  tokenId: "0x1::aptos_coin::AptosCoin", // Aptos Coin type
272
337
  };
273
338
 
339
+ const ethereumParams = undefined;
340
+
274
341
  try {
275
- const { ixs, tx } = await StreamClient.cancel(cancelStreamParams, solanaParams);
342
+ const { ixs, tx } = await StreamClient.cancel(cancelStreamParams, solanaParams);
276
343
  } catch (exception) {
277
- // handle exception
344
+ // handle exception
278
345
  }
279
346
  ```
280
347
 
281
348
  ## Get one stream by its ID
282
349
 
283
350
  ```javascript
351
+ const data: Types.IGetOneData = {
352
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream
353
+ };
354
+
284
355
  try {
285
- const stream = await StreamClient.getOne({
286
- id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA" // Identifier of a stream that is fetched.
287
- });
356
+ const stream = await client.getOne(data);
288
357
  } catch (exception) {
289
- // handle exception
358
+ // handle exception
290
359
  }
291
360
  ```
292
361
 
362
+ ## Fetching unlocked amount
363
+
364
+ ```javascript
365
+ const stream = await client.getOne({
366
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
367
+ });
368
+
369
+ const unlocked = stream.unlocked(tsInSeconds); // bn amount unlocked at the tsInSeconds
370
+ console.log(getNumberFromBN(unlocked, 9));
371
+ ```
372
+
373
+ - Note: unlocked amount is determined based on configuration set on creation, no dynamic data is involved.
374
+
375
+ ## Reading withdrawn amount and remaining funds
376
+
377
+ ```javascript
378
+ const stream = await client.getOne({
379
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
380
+ });
381
+ const withdrawn = stream.withdrawnAmount; // bn amount withdrawn already
382
+ console.log(getNumberFromBN(wihtdrawn, 9));
383
+ const remaining = stream.remaining(9); // amount of remaining funds
384
+ console.log(remaining);
385
+ ```
386
+
293
387
  ## Get multiple streams for a specific wallet address
294
- **NOTE: ONLY SUPPORTED FOR SOLANA CLIENT**
295
388
 
296
389
  ```javascript
390
+ const data: Types.IGetAllData = {
391
+ address: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99",
392
+ type: Types.StreamType.All,
393
+ direction: Types.StreamDirection.All,
394
+ };
395
+
297
396
  try {
298
- const streams = StreamClient.get({
299
- wallet: wallet, // Wallet signing the transaction.
300
- type: StreamType.All, // (optional) Type, default is StreamType.All
301
- direction: StreamDirection.All, // (optional) Direction, default is StreamDirection.All)
302
- });
397
+ const streams = client.get(data);
303
398
  } catch (exception) {
304
- // handle exception
399
+ // handle exception
305
400
  }
306
401
  ```
307
402
 
308
- ## Additional notes
403
+ ## Handling errors
404
+
405
+ Protocol raises custom errors on:
406
+
407
+ - validation errors
408
+ - state missmatch errors (such as canceling a stream that is complete/already canceled)
309
409
 
310
- Streamflow protocol Solana program ID (devnet): `HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ`
410
+ Errors are returned per blockchain specification format.
311
411
 
312
- Streamflow protocol Solana program ID (mainnet): `strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m`
412
+ A public map of protocol errors is available [here](https://streamflow.notion.site/Streamflow-protocol-docs-0accad86d5c44e5db84fd4fb49b8ff54).
313
413
 
314
- Streamflow protocol Aptos program ID (testnet): `0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688`
414
+ ## Additional notes
415
+
416
+ Streamflow protocol program IDs
417
+
418
+ | Solana | |
419
+ | ------- | -------------------------------------------- |
420
+ | Devet | HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ |
421
+ | Mainnet | strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m |
315
422
 
316
- Streamflow protocol Aptos program ID (mainnet): `0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0`
423
+ | EVM | Ethereum(Goerli on Tesnet),Polygon,BNB |
424
+ | ------- | ------------------------------------------ |
425
+ | Testnet | 0x5Db7a43D20De64E3a3BC765334a477026FD13E7d |
426
+ | Mainnet | 0x94d4646Bd307Bf91CB1893BC64d976BF9E60D9B2 |
317
427
 
428
+ | Aptos | |
429
+ | ------- | ------------------------------------------------------------------ |
430
+ | Testnet | 0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688 |
431
+ | Mainnet | 0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0 |
318
432
 
319
433
  **All BN amounts are denominated in their smallest units.**
320
434
 
@@ -324,8 +438,4 @@ And `new BN(1_000_000_000)` is used.
324
438
 
325
439
  Use `getBN` and `getNumberFromBN` utility functions for conversions between `BN` and `Number` types.
326
440
 
327
- **Streamflow Community** (free and open source version, with a limited feature set) is available [here](https://github.com/streamflow-finance/js-sdk/tree/community).
328
-
329
- `npx typedoc packages/stream/index.ts`
330
-
331
441
  WAGMI.
@@ -83,6 +83,11 @@ export interface Stream {
83
83
  canTopup: boolean;
84
84
  name: string;
85
85
  withdrawalFrequency: number;
86
+ closed: boolean;
87
+ currentPauseStart: number;
88
+ pauseCumulative: BN;
89
+ lastRateChangeTime: number;
90
+ fundsUnlockedAtLastRateChange: BN;
86
91
  unlocked(currentTimestamp: number): BN;
87
92
  }
88
93
  export declare class Contract implements Stream {
@@ -123,6 +128,11 @@ export declare class Contract implements Stream {
123
128
  canTopup: boolean;
124
129
  name: string;
125
130
  withdrawalFrequency: number;
131
+ closed: boolean;
132
+ currentPauseStart: number;
133
+ pauseCumulative: BN;
134
+ lastRateChangeTime: number;
135
+ fundsUnlockedAtLastRateChange: BN;
126
136
  constructor(stream: StreamResource, tokenId: string);
127
137
  unlocked(currentTimestamp: number): BN;
128
138
  remaining(decimals: number): number;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Contract = void 0;
7
7
  var bn_js_1 = __importDefault(require("bn.js"));
8
+ var contractUtils_1 = require("../common/contractUtils");
8
9
  var utils_1 = require("../common/utils");
9
10
  var Contract = /** @class */ (function () {
10
11
  function Contract(stream, tokenId) {
@@ -46,15 +47,14 @@ var Contract = /** @class */ (function () {
46
47
  var name = stream.meta.contract_name.replace("0x", "");
47
48
  this.name = Buffer.from(name, "hex").toString("utf8");
48
49
  this.withdrawalFrequency = parseInt(stream.meta.withdrawal_frequency);
50
+ this.closed = stream.closed;
51
+ this.currentPauseStart = parseInt(stream.current_pause_start);
52
+ this.pauseCumulative = new bn_js_1.default(stream.pause_cumulative);
53
+ this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
54
+ this.fundsUnlockedAtLastRateChange = new bn_js_1.default(stream.funds_unlocked_at_last_rate_change);
49
55
  }
50
56
  Contract.prototype.unlocked = function (currentTimestamp) {
51
- var deposited = this.depositedAmount;
52
- if (currentTimestamp < this.cliff)
53
- return new bn_js_1.default(0);
54
- if (currentTimestamp > this.end)
55
- return deposited;
56
- var streamed = this.cliffAmount.add(new bn_js_1.default(Math.floor((currentTimestamp - this.cliff) / this.period)).mul(this.amountPerPeriod));
57
- return streamed.lt(deposited) ? streamed : deposited;
57
+ return (0, contractUtils_1.calculateUnlockedAmount)(this.depositedAmount, this.cliff, this.cliffAmount, this.end, currentTimestamp, this.lastRateChangeTime, this.period, this.amountPerPeriod, this.fundsUnlockedAtLastRateChange);
58
58
  };
59
59
  Contract.prototype.remaining = function (decimals) {
60
60
  return (0, utils_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
@@ -28,35 +28,40 @@ export interface EvmStreamClientOptions {
28
28
  cluster?: ICluster;
29
29
  programId?: string;
30
30
  }
31
- declare type GenericStreamClientOptions = SolanaStreamClientOptions | AptosStreamClientOptions | EvmStreamClientOptions;
32
- export default class GenericStreamClient extends BaseStreamClient {
33
- nativeStreamClient: SolanaStreamClient | AptosStreamClient | EvmStreamClient;
31
+ declare type StreamClientOptions<T extends IChain> = T extends IChain.Solana ? SolanaStreamClientOptions : T extends IChain.Aptos ? AptosStreamClientOptions : EvmStreamClientOptions;
32
+ declare type StreamClientType<T extends IChain> = T extends IChain.Solana ? SolanaStreamClient : T extends IChain.Aptos ? AptosStreamClient : EvmStreamClient;
33
+ declare type ChainSpecificParams<T, SolanaExt, AptosExt> = T extends SolanaStreamClient ? SolanaExt : T extends AptosStreamClient ? AptosExt : undefined;
34
+ declare type CreateSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, ICreateStreamSolanaExt, ICreateStreamAptosExt>;
35
+ declare type TopupSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, ITopUpStreamSolanaExt, ITransactionAptosExt>;
36
+ declare type InteractSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, IInteractStreamSolanaExt, ITransactionAptosExt>;
37
+ export default class GenericStreamClient<T extends IChain> extends BaseStreamClient {
38
+ nativeStreamClient: StreamClientType<T>;
34
39
  chain: IChain;
35
- constructor(options: GenericStreamClientOptions);
40
+ constructor(options: StreamClientOptions<T>);
36
41
  /**
37
42
  * Creates a new stream/vesting contract.
38
43
  */
39
- create(streamData: ICreateStreamData, chainSpecificParams: ICreateStreamAptosExt | ICreateStreamSolanaExt): Promise<ICreateResult>;
44
+ create(streamData: ICreateStreamData, chainSpecificParams?: CreateSpecificParams<T>): Promise<ICreateResult>;
40
45
  /**
41
46
  * Creates multiple stream/vesting contracts.
42
47
  */
43
- createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: ICreateStreamAptosExt | ICreateStreamSolanaExt): Promise<IMultiTransactionResult>;
48
+ createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams?: CreateSpecificParams<T>): Promise<IMultiTransactionResult>;
44
49
  /**
45
50
  * Attempts withdrawing from the specified stream.
46
51
  */
47
- withdraw(withdrawData: IWithdrawData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<ITransactionResult>;
52
+ withdraw(withdrawData: IWithdrawData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
48
53
  /**
49
54
  * Attempts canceling the specified stream.
50
55
  */
51
- cancel(cancelData: ICancelData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<ITransactionResult>;
56
+ cancel(cancelData: ICancelData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
52
57
  /**
53
58
  * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
54
59
  */
55
- transfer(transferData: ITransferData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<ITransactionResult>;
60
+ transfer(transferData: ITransferData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
56
61
  /**
57
62
  * Tops up stream account with specified amount.
58
63
  */
59
- topup(topupData: ITopUpData, chainSpecificParams: ITransactionAptosExt | ITopUpStreamSolanaExt): Promise<ITransactionResult>;
64
+ topup(topupData: ITopUpData, chainSpecificParams?: TopupSpecificParams<T>): Promise<ITransactionResult>;
60
65
  /**
61
66
  * Fetch stream data by its id (address).
62
67
  */
@@ -68,6 +73,6 @@ export default class GenericStreamClient extends BaseStreamClient {
68
73
  /**
69
74
  * Attempts updating the stream auto withdrawal params and amount per period
70
75
  */
71
- update(updateData: IUpdateData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<ITransactionResult>;
76
+ update(updateData: IUpdateData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
72
77
  }
73
78
  export {};
@@ -48,78 +48,72 @@ var GenericStreamClient = /** @class */ (function (_super) {
48
48
  */
49
49
  GenericStreamClient.prototype.create = function (streamData, chainSpecificParams) {
50
50
  if (this.nativeStreamClient instanceof StreamClient_1.default) {
51
- var params = chainSpecificParams;
52
- return this.nativeStreamClient.create(streamData, params);
51
+ return this.nativeStreamClient.create(streamData, chainSpecificParams);
53
52
  }
54
- else {
55
- var params = chainSpecificParams;
56
- return this.nativeStreamClient.create(streamData, params);
53
+ else if (this.nativeStreamClient instanceof StreamClient_2.default) {
54
+ return this.nativeStreamClient.create(streamData, chainSpecificParams);
57
55
  }
56
+ return this.nativeStreamClient.create(streamData);
58
57
  };
59
58
  /**
60
59
  * Creates multiple stream/vesting contracts.
61
60
  */
62
61
  GenericStreamClient.prototype.createMultiple = function (multipleStreamData, chainSpecificParams) {
63
62
  if (this.nativeStreamClient instanceof StreamClient_1.default) {
64
- var params = chainSpecificParams;
65
- return this.nativeStreamClient.createMultiple(multipleStreamData, params);
63
+ return this.nativeStreamClient.createMultiple(multipleStreamData, chainSpecificParams);
66
64
  }
67
- else {
68
- var params = chainSpecificParams;
69
- return this.nativeStreamClient.createMultiple(multipleStreamData, params);
65
+ else if (this.nativeStreamClient instanceof StreamClient_2.default) {
66
+ return this.nativeStreamClient.createMultiple(multipleStreamData, chainSpecificParams);
70
67
  }
68
+ return this.nativeStreamClient.createMultiple(multipleStreamData);
71
69
  };
72
70
  /**
73
71
  * Attempts withdrawing from the specified stream.
74
72
  */
75
73
  GenericStreamClient.prototype.withdraw = function (withdrawData, chainSpecificParams) {
76
74
  if (this.nativeStreamClient instanceof StreamClient_1.default) {
77
- var params = chainSpecificParams;
78
- return this.nativeStreamClient.withdraw(withdrawData, params);
75
+ return this.nativeStreamClient.withdraw(withdrawData, chainSpecificParams);
79
76
  }
80
- else {
81
- var params = chainSpecificParams;
82
- return this.nativeStreamClient.withdraw(withdrawData, params);
77
+ else if (this.nativeStreamClient instanceof StreamClient_2.default) {
78
+ return this.nativeStreamClient.withdraw(withdrawData, chainSpecificParams);
83
79
  }
80
+ return this.nativeStreamClient.withdraw(withdrawData);
84
81
  };
85
82
  /**
86
83
  * Attempts canceling the specified stream.
87
84
  */
88
85
  GenericStreamClient.prototype.cancel = function (cancelData, chainSpecificParams) {
89
86
  if (this.nativeStreamClient instanceof StreamClient_1.default) {
90
- var params = chainSpecificParams;
91
- return this.nativeStreamClient.cancel(cancelData, params);
87
+ return this.nativeStreamClient.cancel(cancelData, chainSpecificParams);
92
88
  }
93
- else {
94
- var params = chainSpecificParams;
95
- return this.nativeStreamClient.cancel(cancelData, params);
89
+ else if (this.nativeStreamClient instanceof StreamClient_2.default) {
90
+ return this.nativeStreamClient.cancel(cancelData, chainSpecificParams);
96
91
  }
92
+ return this.nativeStreamClient.cancel(cancelData);
97
93
  };
98
94
  /**
99
95
  * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
100
96
  */
101
97
  GenericStreamClient.prototype.transfer = function (transferData, chainSpecificParams) {
102
98
  if (this.nativeStreamClient instanceof StreamClient_1.default) {
103
- var params = chainSpecificParams;
104
- return this.nativeStreamClient.transfer(transferData, params);
99
+ return this.nativeStreamClient.transfer(transferData, chainSpecificParams);
105
100
  }
106
- else {
107
- var params = chainSpecificParams;
108
- return this.nativeStreamClient.transfer(transferData, params);
101
+ else if (this.nativeStreamClient instanceof StreamClient_2.default) {
102
+ return this.nativeStreamClient.transfer(transferData, chainSpecificParams);
109
103
  }
104
+ return this.nativeStreamClient.transfer(transferData);
110
105
  };
111
106
  /**
112
107
  * Tops up stream account with specified amount.
113
108
  */
114
109
  GenericStreamClient.prototype.topup = function (topupData, chainSpecificParams) {
115
110
  if (this.nativeStreamClient instanceof StreamClient_1.default) {
116
- var params = chainSpecificParams;
117
- return this.nativeStreamClient.topup(topupData, params);
111
+ return this.nativeStreamClient.topup(topupData, chainSpecificParams);
118
112
  }
119
- else {
120
- var params = chainSpecificParams;
121
- return this.nativeStreamClient.topup(topupData, params);
113
+ else if (this.nativeStreamClient instanceof StreamClient_2.default) {
114
+ return this.nativeStreamClient.topup(topupData, chainSpecificParams);
122
115
  }
116
+ return this.nativeStreamClient.topup(topupData);
123
117
  };
124
118
  /**
125
119
  * Fetch stream data by its id (address).
@@ -138,13 +132,12 @@ var GenericStreamClient = /** @class */ (function (_super) {
138
132
  */
139
133
  GenericStreamClient.prototype.update = function (updateData, chainSpecificParams) {
140
134
  if (this.nativeStreamClient instanceof StreamClient_1.default) {
141
- var params = chainSpecificParams;
142
- return this.nativeStreamClient.update(updateData, params);
135
+ return this.nativeStreamClient.update(updateData, chainSpecificParams);
143
136
  }
144
- else {
145
- var params = chainSpecificParams;
146
- return this.nativeStreamClient.update(updateData, params);
137
+ else if (this.nativeStreamClient instanceof StreamClient_2.default) {
138
+ return this.nativeStreamClient.update(updateData, chainSpecificParams);
147
139
  }
140
+ return this.nativeStreamClient.update(updateData);
148
141
  };
149
142
  return GenericStreamClient;
150
143
  }(BaseStreamClient_1.BaseStreamClient));
@@ -0,0 +1,2 @@
1
+ import BN from "bn.js";
2
+ export declare const calculateUnlockedAmount: (depositedAmount: BN, cliff: number, cliffAmount: BN, end: number, currentTimestamp: number, lastRateChangeTime: number, period: number, amountPerPeriod: BN, fundsUnlockedAtLastRateChange: BN) => BN;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.calculateUnlockedAmount = void 0;
7
+ var bn_js_1 = __importDefault(require("bn.js"));
8
+ var calculateUnlockedAmount = function (depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange) {
9
+ var deposited = depositedAmount;
10
+ if (currentTimestamp < cliff)
11
+ return new bn_js_1.default(0);
12
+ if (currentTimestamp > end)
13
+ return deposited;
14
+ var savedUnlockedFunds = lastRateChangeTime === 0 ? cliffAmount : fundsUnlockedAtLastRateChange;
15
+ var savedUnlockedFundsTime = lastRateChangeTime === 0 ? cliff : lastRateChangeTime;
16
+ var streamed = new bn_js_1.default(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period))
17
+ .mul(amountPerPeriod)
18
+ .add(savedUnlockedFunds);
19
+ return streamed.lt(deposited) ? streamed : deposited;
20
+ };
21
+ exports.calculateUnlockedAmount = calculateUnlockedAmount;
@@ -96,6 +96,7 @@ export declare enum IChain {
96
96
  Aptos = "Aptos",
97
97
  Ethereum = "Ethereum",
98
98
  BNB = "BNB",
99
- Polygon = "Polygon"
99
+ Polygon = "Polygon",
100
+ Sui = "Sui"
100
101
  }
101
102
  export {};
@@ -28,4 +28,5 @@ var IChain;
28
28
  IChain["Ethereum"] = "Ethereum";
29
29
  IChain["BNB"] = "BNB";
30
30
  IChain["Polygon"] = "Polygon";
31
+ IChain["Sui"] = "Sui";
31
32
  })(IChain = exports.IChain || (exports.IChain = {}));
@@ -133,7 +133,7 @@ var EvmStreamClient = /** @class */ (function (_super) {
133
133
  }
134
134
  EvmStreamClient.prototype.create = function (streamData) {
135
135
  return __awaiter(this, void 0, void 0, function () {
136
- var multiParams, fees, args, result, confirmedTx, metadataId;
136
+ var multiParams, fees, args, sum, tokenContract, approvalTx, result, confirmedTx, metadataId;
137
137
  var _a, _b;
138
138
  return __generator(this, function (_c) {
139
139
  switch (_c.label) {
@@ -145,13 +145,21 @@ var EvmStreamClient = /** @class */ (function (_super) {
145
145
  return [4 /*yield*/, this.generateMultiPayloads(multiParams)];
146
146
  case 2:
147
147
  args = (_c.sent())[0];
148
- return [4 /*yield*/, (_b = this.writeContract).create.apply(_b, __spreadArray(__spreadArray([], __read(args), false), [{ value: fees.value }], false))];
148
+ sum = streamData.amount.mul(new bn_js_1.BN(constants_2.BASE_FEE)).div(new bn_js_1.BN(1000000));
149
+ tokenContract = new ethers_1.ethers.Contract(streamData.tokenId, ercAbi_1.default, this.signer);
150
+ return [4 /*yield*/, tokenContract.approve(this.programId, sum.toString())];
149
151
  case 3:
152
+ approvalTx = _c.sent();
153
+ return [4 /*yield*/, approvalTx.wait()];
154
+ case 4:
155
+ _c.sent();
156
+ return [4 /*yield*/, (_b = this.writeContract).create.apply(_b, __spreadArray(__spreadArray([], __read(args), false), [{ value: fees.value }], false))];
157
+ case 5:
150
158
  result = _c.sent();
151
159
  return [4 /*yield*/, result.wait()];
152
- case 4:
160
+ case 6:
153
161
  confirmedTx = _c.sent();
154
- metadataId = this.formatMetadataId(confirmedTx.logs[confirmedTx.logs.length - 1].data);
162
+ metadataId = this.formatMetadataId(confirmedTx.events.find(function (item) { return item.event === "ContractCreated"; }).args[0]);
155
163
  return [2 /*return*/, {
156
164
  ixs: [],
157
165
  txId: result.hash,
@@ -163,7 +171,7 @@ var EvmStreamClient = /** @class */ (function (_super) {
163
171
  };
164
172
  EvmStreamClient.prototype.createMultiple = function (multipleStreamData) {
165
173
  return __awaiter(this, void 0, void 0, function () {
166
- var fees, args, creationPromises, signatures, results, confirmations, successes, metadatas, metadataToRecipient, failures;
174
+ var fees, args, sum, tokenContract, approvalTx, creationPromises, signatures, results, confirmations, successes, metadatas, metadataToRecipient, failures;
167
175
  var _a;
168
176
  var _this = this;
169
177
  return __generator(this, function (_b) {
@@ -174,16 +182,27 @@ var EvmStreamClient = /** @class */ (function (_super) {
174
182
  return [4 /*yield*/, this.generateMultiPayloads(multipleStreamData)];
175
183
  case 2:
176
184
  args = _b.sent();
185
+ sum = multipleStreamData.recipients
186
+ .reduce(function (acc, v) { return acc.add(v.amount); }, new bn_js_1.BN(0))
187
+ .mul(new bn_js_1.BN(constants_2.BASE_FEE))
188
+ .div(new bn_js_1.BN(1000000));
189
+ tokenContract = new ethers_1.ethers.Contract(multipleStreamData.tokenId, ercAbi_1.default, this.signer);
190
+ return [4 /*yield*/, tokenContract.approve(this.programId, sum.toString())];
191
+ case 3:
192
+ approvalTx = _b.sent();
193
+ return [4 /*yield*/, approvalTx.wait()];
194
+ case 4:
195
+ _b.sent();
177
196
  creationPromises = args.map(function (item) {
178
197
  var _a;
179
198
  return (_a = _this.writeContract).create.apply(_a, __spreadArray(__spreadArray([], __read(item), false), [{ value: fees.value }], false));
180
199
  });
181
200
  signatures = [];
182
201
  return [4 /*yield*/, Promise.all(creationPromises)];
183
- case 3:
202
+ case 5:
184
203
  results = _b.sent();
185
204
  return [4 /*yield*/, Promise.allSettled(results.map(function (result) { return result.wait(); }))];
186
- case 4:
205
+ case 6:
187
206
  confirmations = _b.sent();
188
207
  successes = confirmations
189
208
  .filter(function (el) { return el.status === "fulfilled"; })
@@ -191,7 +210,8 @@ var EvmStreamClient = /** @class */ (function (_super) {
191
210
  signatures.push.apply(signatures, __spreadArray([], __read(successes.map(function (el) { return el.hash; })), false));
192
211
  metadatas = confirmations.map(function (result) {
193
212
  return result.status === "fulfilled"
194
- ? _this.formatMetadataId(result.value.logs[result.value.logs.length - 1].data)
213
+ ? _this.formatMetadataId(result.value.events.find(function (item) { return item.event === "ContractCreated"; })
214
+ .args[0])
195
215
  : null;
196
216
  });
197
217
  metadataToRecipient = metadatas.reduce(function (acc, value, index) {
@@ -80,6 +80,11 @@ export interface Stream {
80
80
  canTopup: boolean;
81
81
  name: string;
82
82
  withdrawalFrequency: number;
83
+ closed: boolean;
84
+ currentPauseStart: number;
85
+ pauseCumulative: BN;
86
+ lastRateChangeTime: number;
87
+ fundsUnlockedAtLastRateChange: BN;
83
88
  unlocked(currentTimestamp: number, decimals: number): BN;
84
89
  }
85
90
  export declare class EvmContract implements Stream {
@@ -120,6 +125,11 @@ export declare class EvmContract implements Stream {
120
125
  canTopup: boolean;
121
126
  name: string;
122
127
  withdrawalFrequency: number;
128
+ closed: boolean;
129
+ currentPauseStart: number;
130
+ pauseCumulative: BN;
131
+ lastRateChangeTime: number;
132
+ fundsUnlockedAtLastRateChange: BN;
123
133
  constructor(stream: StreamAbiResult);
124
134
  unlocked(currentTimestamp: number): BN;
125
135
  remaining(decimals: number): number;
package/dist/evm/types.js CHANGED
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.EvmContract = void 0;
7
7
  var bn_js_1 = __importDefault(require("bn.js"));
8
+ var contractUtils_1 = require("../common/contractUtils");
8
9
  var utils_1 = require("../common/utils");
9
10
  var EvmContract = /** @class */ (function () {
10
11
  function EvmContract(stream) {
@@ -45,15 +46,14 @@ var EvmContract = /** @class */ (function () {
45
46
  this.canTopup = stream.meta.can_topup;
46
47
  this.name = stream.meta.contract_name;
47
48
  this.withdrawalFrequency = stream.meta.withdrawal_frequency.toNumber();
49
+ this.closed = stream.closed;
50
+ this.currentPauseStart = stream.current_pause_start.toNumber();
51
+ this.pauseCumulative = new bn_js_1.default(stream.pause_cumulative.toString());
52
+ this.lastRateChangeTime = stream.last_rate_change_time.toNumber();
53
+ this.fundsUnlockedAtLastRateChange = new bn_js_1.default(stream.funds_unlocked_at_last_rate_change.toString());
48
54
  }
49
55
  EvmContract.prototype.unlocked = function (currentTimestamp) {
50
- var deposited = this.depositedAmount;
51
- if (currentTimestamp < this.cliff)
52
- return new bn_js_1.default(0);
53
- if (currentTimestamp > this.end)
54
- return deposited;
55
- var streamed = this.cliffAmount.add(new bn_js_1.default(Math.floor((currentTimestamp - this.cliff) / this.period)).mul(this.amountPerPeriod));
56
- return streamed.lt(deposited) ? streamed : deposited;
56
+ return (0, contractUtils_1.calculateUnlockedAmount)(this.depositedAmount, this.cliff, this.cliffAmount, this.end, currentTimestamp, this.lastRateChangeTime, this.period, this.amountPerPeriod, this.fundsUnlockedAtLastRateChange);
57
57
  };
58
58
  EvmContract.prototype.remaining = function (decimals) {
59
59
  return (0, utils_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * as StreamflowSolana from "./solana";
2
2
  export * as StreamflowAptos from "./aptos";
3
+ export * as StreamflowEVM from "./evm";
3
4
  export * as Types from "./common/types";
4
5
  export * from "./common/utils";
5
6
  export { default as GenericStreamClient } from "./common/GenericStreamClient";
package/dist/index.js CHANGED
@@ -29,9 +29,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.GenericStreamClient = exports.Types = exports.StreamflowAptos = exports.StreamflowSolana = void 0;
32
+ exports.GenericStreamClient = exports.Types = exports.StreamflowEVM = exports.StreamflowAptos = exports.StreamflowSolana = void 0;
33
33
  exports.StreamflowSolana = __importStar(require("./solana"));
34
34
  exports.StreamflowAptos = __importStar(require("./aptos"));
35
+ exports.StreamflowEVM = __importStar(require("./evm"));
35
36
  exports.Types = __importStar(require("./common/types"));
36
37
  __exportStar(require("./common/utils"), exports);
37
38
  var GenericStreamClient_1 = require("./common/GenericStreamClient");
@@ -2,6 +2,7 @@ import { PublicKey } from "@solana/web3.js";
2
2
  export declare const TX_FINALITY_CONFIRMED = "confirmed";
3
3
  export declare const STREAM_STRUCT_OFFSET_SENDER = 49;
4
4
  export declare const STREAM_STRUCT_OFFSET_RECIPIENT = 113;
5
+ export declare const CREATE_PARAMS_PADDING = 126;
5
6
  export declare const PROGRAM_ID: {
6
7
  devnet: string;
7
8
  mainnet: string;
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.BASE_FEE = exports.AIRDROP_AMOUNT = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = 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;
4
+ exports.BASE_FEE = exports.AIRDROP_AMOUNT = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.STREAMFLOW_DEVNET_PROGRAM_ID = exports.STREAMFLOW_PROGRAM_ID = exports.PROGRAM_ID = exports.CREATE_PARAMS_PADDING = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
5
5
  var web3_js_1 = require("@solana/web3.js");
6
6
  var types_1 = require("../common/types");
7
7
  exports.TX_FINALITY_CONFIRMED = "confirmed";
8
8
  exports.STREAM_STRUCT_OFFSET_SENDER = 49;
9
9
  exports.STREAM_STRUCT_OFFSET_RECIPIENT = 113;
10
+ // Defined: https://github.com/streamflow-finance/protocol/blob/main/programs/protocol/src/state.rs#L25
11
+ exports.CREATE_PARAMS_PADDING = 126;
10
12
  exports.PROGRAM_ID = (_a = {},
11
13
  _a[types_1.ICluster.Devnet] = "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
12
14
  _a[types_1.ICluster.Mainnet] = "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m",
@@ -36,6 +36,16 @@ export interface IStreamLayout {
36
36
  can_topup: number;
37
37
  stream_name: Uint8Array;
38
38
  withdraw_frequency: Uint8Array;
39
+ ghost: Uint8Array;
40
+ pausable: number;
41
+ can_update_rate: number;
42
+ create_params_padding_length: number;
43
+ create_params_padding: number[];
44
+ closed: number;
45
+ current_pause_start: Uint8Array;
46
+ pause_cumulative: Uint8Array;
47
+ last_rate_change_time: Uint8Array;
48
+ funds_unlocked_at_last_rate_change: Uint8Array;
39
49
  }
40
50
  export interface ICreateStreamLayout {
41
51
  start_time: Uint8Array;
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.topupStreamLayout = exports.encodeUpdateStream = exports.withdrawStreamLayout = exports.createUncheckedStreamLayout = exports.createStreamLayout = exports.streamLayout = void 0;
27
27
  var BufferLayout = __importStar(require("@solana/buffer-layout"));
28
+ var constants_1 = require("./constants");
28
29
  /**
29
30
  * Stream layout
30
31
  */
@@ -66,6 +67,17 @@ exports.streamLayout = BufferLayout.struct([
66
67
  BufferLayout.u8("can_topup"),
67
68
  BufferLayout.blob(64, "stream_name"),
68
69
  BufferLayout.blob(8, "withdraw_frequency"),
70
+ // Unused, kept for backward compatibility™
71
+ BufferLayout.blob(4, "ghost"),
72
+ BufferLayout.u8("pausable"),
73
+ BufferLayout.u8("can_update_rate"),
74
+ BufferLayout.blob(4, "create_stream_params_padding_length"),
75
+ BufferLayout.seq(BufferLayout.u8(), constants_1.CREATE_PARAMS_PADDING, "create_params_padding"),
76
+ BufferLayout.u8("closed"),
77
+ BufferLayout.blob(8, "current_pause_start"),
78
+ BufferLayout.blob(8, "pause_cumulative"),
79
+ BufferLayout.blob(8, "last_rate_change_time"),
80
+ BufferLayout.blob(8, "funds_unlocked_at_last_rate_change"),
69
81
  ]);
70
82
  /**
71
83
  * Create stream instruction layout
@@ -171,6 +171,11 @@ export interface Stream {
171
171
  canTopup: boolean;
172
172
  name: string;
173
173
  withdrawalFrequency: number;
174
+ closed: boolean;
175
+ currentPauseStart: number;
176
+ pauseCumulative: BN;
177
+ lastRateChangeTime: number;
178
+ fundsUnlockedAtLastRateChange: BN;
174
179
  unlocked(currentTimestamp: number): BN;
175
180
  }
176
181
  export declare class Contract implements Stream {
@@ -211,6 +216,11 @@ export declare class Contract implements Stream {
211
216
  canTopup: boolean;
212
217
  name: string;
213
218
  withdrawalFrequency: number;
219
+ closed: boolean;
220
+ currentPauseStart: number;
221
+ pauseCumulative: BN;
222
+ lastRateChangeTime: number;
223
+ fundsUnlockedAtLastRateChange: BN;
214
224
  constructor(stream: DecodedStream);
215
225
  unlocked(currentTimestamp: number): BN;
216
226
  remaining(decimals: number): number;
@@ -253,6 +263,11 @@ export interface DecodedStream {
253
263
  canTopup: boolean;
254
264
  name: string;
255
265
  withdrawFrequency: BN;
266
+ closed: boolean;
267
+ currentPauseStart: BN;
268
+ pauseCumulative: BN;
269
+ lastRateChangeTime: BN;
270
+ fundsUnlockedAtLastRateChange: BN;
256
271
  }
257
272
  export interface TransactionResponse {
258
273
  tx: TransactionSignature;
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.TransferCancelOptions = exports.Contract = exports.Cluster = void 0;
7
- var bn_js_1 = __importDefault(require("bn.js"));
4
+ var contractUtils_1 = require("../common/contractUtils");
8
5
  var utils_1 = require("../common/utils");
9
6
  var wallet_adapter_base_1 = require("@solana/wallet-adapter-base");
10
7
  Object.defineProperty(exports, "Cluster", { enumerable: true, get: function () { return wallet_adapter_base_1.WalletAdapterNetwork; } });
@@ -48,15 +45,14 @@ var Contract = /** @class */ (function () {
48
45
  this.canTopup = stream.canTopup;
49
46
  this.name = stream.name;
50
47
  this.withdrawalFrequency = stream.withdrawFrequency.toNumber();
48
+ this.closed = stream.closed;
49
+ this.currentPauseStart = stream.currentPauseStart.toNumber();
50
+ this.pauseCumulative = stream.pauseCumulative;
51
+ this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
52
+ this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
51
53
  }
52
54
  Contract.prototype.unlocked = function (currentTimestamp) {
53
- var deposited = this.depositedAmount;
54
- if (currentTimestamp < this.cliff)
55
- return new bn_js_1.default(0);
56
- if (currentTimestamp > this.end)
57
- return deposited;
58
- var streamed = this.cliffAmount.add(new bn_js_1.default(Math.floor((currentTimestamp - this.cliff) / this.period)).mul(this.amountPerPeriod));
59
- return streamed.lt(deposited) ? streamed : deposited;
55
+ return (0, contractUtils_1.calculateUnlockedAmount)(this.depositedAmount, this.cliff, this.cliffAmount, this.end, currentTimestamp, this.lastRateChangeTime, this.period, this.amountPerPeriod, this.fundsUnlockedAtLastRateChange);
60
56
  };
61
57
  Contract.prototype.remaining = function (decimals) {
62
58
  return (0, utils_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
@@ -98,6 +98,11 @@ var decodeStream = function (buf) {
98
98
  canTopup: Boolean(raw.can_topup),
99
99
  name: decoder.decode(raw.stream_name),
100
100
  withdrawFrequency: new bn_js_1.default(raw.withdraw_frequency, LE),
101
+ closed: Boolean(raw.closed),
102
+ currentPauseStart: new bn_js_1.default(raw.current_pause_start, LE),
103
+ pauseCumulative: new bn_js_1.default(raw.pause_cumulative, LE),
104
+ lastRateChangeTime: new bn_js_1.default(raw.last_rate_change_time, LE),
105
+ fundsUnlockedAtLastRateChange: new bn_js_1.default(raw.funds_unlocked_at_last_rate_change, LE),
101
106
  };
102
107
  };
103
108
  exports.decodeStream = decodeStream;
@@ -143,6 +148,11 @@ var formatDecodedStream = function (stream) {
143
148
  canTopup: stream.canTopup,
144
149
  name: stream.name,
145
150
  withdrawalFrequency: stream.withdrawFrequency.toNumber(),
151
+ closed: stream.closed,
152
+ currentPauseStart: stream.currentPauseStart.toNumber(),
153
+ pauseCumulative: stream.pauseCumulative,
154
+ lastRateChangeTime: stream.lastRateChangeTime.toNumber(),
155
+ fundsUnlockedAtLastRateChange: stream.fundsUnlockedAtLastRateChange,
146
156
  unlocked: function () {
147
157
  return new bn_js_1.default(0);
148
158
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "4.1.0-beta.9",
3
+ "version": "5.0.1",
4
4
  "description": "JavaScript SDK to interact with Streamflow protocol.",
5
5
  "main": "dist/index.js",
6
6
  "homepage": "https://github.com/streamflow-finance/js-sdk/",
@@ -40,4 +40,4 @@
40
40
  "ethers": "5.7.2",
41
41
  "js-sha256": "0.9.0"
42
42
  }
43
- }
43
+ }