@streamflow/stream 4.0.0-Alpha.3 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,9 +25,12 @@ You can also `getOne` stream and `get` multiple streams.
25
25
 
26
26
  ## Installation
27
27
 
28
- `npm i @streamflow/stream @solana/web3.js @project-serum/anchor`
28
+ `npm i -s @streamflow/stream`
29
+
30
+ or
31
+
32
+ `yarn add @streamflow/stream`
29
33
 
30
- > _Anchor is needed for the `Wallet` type. We plan on removing this dependency in upcoming releases._
31
34
 
32
35
  ## Import SDK
33
36
 
@@ -35,21 +38,10 @@ Most common imports:
35
38
 
36
39
  ```javascript
37
40
  import {
38
- StreamClient,
39
- Stream,
40
- CreateParams,
41
- CreateMultiParams,
42
- WithdrawParams,
43
- TransferParams,
44
- TopupParams,
45
- CancelParams,
46
- GetAllParams,
47
- StreamDirection,
48
- StreamType,
49
- Cluster,
50
- TxResponse,
51
- CreateResponse,
52
- BN,
41
+ GenericStreamClient,
42
+ StreamflowSolana,
43
+ StreamflowAptos,
44
+ Types,
53
45
  getBN,
54
46
  getNumberFromBN,
55
47
  } from "@streamflow/stream";
@@ -59,45 +51,82 @@ _Check the SDK for other types and utility functions._
59
51
 
60
52
  ## Create StreamClient instance
61
53
 
62
- Before creating and manipulating streams StreamClient instance must be created.
54
+ Before creating and manipulating streams chain specific or generic StreamClient instance must be created.
63
55
  All streams functions are methods on this instance.
64
56
 
57
+ ### Solana
65
58
  ```javascript
66
- import { StreamClient } from "@streamflow/stream";
59
+ import { StreamflowSolana, Types } from "@streamflow/stream";
67
60
 
68
- const StreamClient = new StreamClient(
69
- "https://api.mainnet-beta.solana.com",
70
- Cluster.Mainnet,
71
- "confirmed"
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
72
65
  );
73
66
  ```
67
+ ### Aptos
68
+ ```javascript
69
+ import { StreamflowAptos, Types } from "@streamflow/stream";
70
+
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
75
+ );
76
+ ```
77
+ ### Generic Stream Client
78
+ Provides isomorphic interface to work with streams agnostic of chain.
79
+ ```javascript
80
+ import { GenericStreamClient, Types } from "@streamflow/stream";
81
+
82
+ const StreamClient = new StreamClient({
83
+ chain: Types.IChain.Aptos, // Blockchain
84
+ clusterUrl: "https://fullnode.mainnet.aptoslabs.com/v1", // RPC cluster URL
85
+ cluster: Types.ICluster.Mainnet, // (optional) (default: Mainnet)
86
+ // ...rest chain specific params e.g. commitment for Solana
87
+ });
88
+ ```
89
+
90
+ All the examples below will contain generic method options descriptions and chain specific params.
74
91
 
92
+
93
+ > NOTE: All timestamp parameters are in seconds.
75
94
  ## Create stream
76
95
 
77
96
  ```javascript
78
97
  const createStreamParams = {
79
- sender: wallet, // Wallet/Keypair signing the transaction, creating and sending the stream.
80
- recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Solana recipient address.
81
- mint: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // SPL Token mint.
82
- start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
83
- depositedAmount: getBN(1000000000000, 9), // Deposited amount of tokens (using smallest denomination).
84
- period: 1, // Time step (period) in seconds per which the unlocking occurs.
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.
85
102
  cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds.
86
- cliffAmount: new BN(100000000000), // Amount (smallest denomination) unlocked at the "cliff" timestamp.
87
- amountPerPeriod: getBN(5000000000, 9), // Release rate: how many tokens are unlocked per each period.
103
+ cliffAmount: getBN(100_000, 9),// Amount (smallest denomination) unlocked at the "cliff" timestamp.
88
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.
89
107
  canTopup: false, // setting to FALSE will effectively create a vesting contract.
90
- cancelableBySender: true, // Whether or not sender can cancel the stream.
91
- cancelableByRecipient: false, // Whether or not recipient can cancel the stream.
92
- transferableBySender: true, // Whether or not sender can transfer the stream.
93
- transferableByRecipient: false, // Whether or not recipient can transfer the stream.
94
- automaticWithdrawal: true, // [WIP] Whether or not a 3rd party (e.g. cron job, "cranker") can initiate a token withdraw/transfer.
95
- withdrawalFrequency: 10, // [WIP] 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.
96
- partner: null, // (optional) Partner's wallet address (string | null).
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
116
+ };
117
+
118
+ const solanaParams = {
119
+ sender: wallet, // SignerWalletAdapter or Keypair of Sender account
120
+ partner: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // [optional] Partner Solana address
121
+ isNative: // [optional] [WILL CREATE A wSOL STREAM] Wether Stream or Vesting should be paid with Solana native token or not
122
+ };
123
+
124
+ const aptosParams = {
125
+ senderWallet: wallet, // AptosWalletAdapter Wallet of sender
97
126
  };
98
127
 
99
128
  try {
100
- const { ixs, tx, metadata } = await StreamClient.create(createStreamParams);
129
+ const { ixs, tx, metadata } = await solanaStreamClient.create(createStreamParams, solanaParams);
101
130
  } catch (exception) {
102
131
  // handle exception
103
132
  }
@@ -108,52 +137,68 @@ try {
108
137
  ```javascript
109
138
  const recipients = [
110
139
  {
111
- recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Solana recipient address.
112
- depositedAmount: getBN(1000000000000, 9), // Deposited amount of tokens (in the smallest units).
113
- name: "January Payroll", // The stream name/subject.
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.
114
145
  },
146
+ // ... Other Recipient options
115
147
  ];
116
148
 
117
149
  const createMultiStreamsParams = {
118
- sender: wallet, // Wallet/Keypair signing the transaction, creating and sending the stream.
119
- recipientsData: recipients, // Array of Solana recipient address.
120
- mint: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // SPL Token mint.
121
- start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
122
- period: 1, // Time step (period) in seconds per which the unlocking occurs.
150
+ tokenId: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // SPL token mint or Aptos Coin type
123
151
  cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds.
124
- cliffAmount: getBN(100000000000, 9), // Amount unlocked at the "cliff" timestamp.
125
- amountPerPeriod: getBN(5000000000, 9), // Release rate: how many tokens are unlocked per each period.
126
- canTopup: true, // setting to FALSE will effectively create a vesting contract.
127
- cancelableBySender: true, // Whether or not sender can cancel the stream.
128
- cancelableByRecipient: false, // Whether or not recipient can cancel the stream.
129
- transferableBySender: true, // Whether or not sender can transfer the stream.
130
- transferableByRecipient: false, // Whether or not recipient can transfer the stream.
131
- automaticWithdrawal: false, // Whether or not a 3rd party can initiate withdraw in the name of recipient (currently not used, set it to FALSE).
132
- partner: null, // (optional) Partner's wallet address (string | null).
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
163
+ };
164
+
165
+ const solanaParams = {
166
+ sender: wallet, // SignerWalletAdapter or Keypair of Sender account
167
+ partner: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // [optional] Partner Solana address
168
+ isNative: // [optional] [WILL CREATE A wSOL STREAM] Wether Stream or Vesting should be paid with Solana native token or not
169
+ };
170
+
171
+ const aptosParams = {
172
+ senderWallet: wallet, // AptosWalletAdapter Wallet of sender
133
173
  };
134
174
 
135
175
  try {
136
- const { txs } = await StreamClient.createMultiple(createMultiStreamsParams);
176
+ const { txs } = await StreamClient.createMultiple(createMultiStreamsParams, solanaParams);
137
177
  } catch (exception) {
138
178
  // handle exception
139
179
  }
140
180
  ```
141
181
 
142
- \_Disclaimer: Support for scheduled, automatic token withdrawals/transfers is under development and scheduled to launch in Q1. Once launched, it will be enabled retroactively for all streams that have `automaticWithdrawal` set to `true`.
143
-
144
- Please note that transaction fees for the scheduled transfers are paid upfront by the stream creator (sender).\_
145
-
146
182
  ## Withdraw from stream
147
183
 
148
184
  ```javascript
149
185
  const withdrawStreamParams = {
150
- invoker: wallet, // Wallet/Keypair signing the transaction.
151
186
  id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be withdrawn from.
152
187
  amount: getBN(100000000000, 9), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
153
188
  };
154
189
 
190
+ const solanaParams = {
191
+ invoker: wallet, // Wallet/Keypair signing the transaction.
192
+ };
193
+
194
+ const aptosParams = {
195
+ senderWallet: wallet, // AptosWalletAdapter Wallet of sender
196
+ tokenId: "0x1::aptos_coin::AptosCoin", // Aptos Coin type
197
+ };
198
+
199
+
155
200
  try {
156
- const { ixs, tx } = await StreamClient.withdraw(withdrawStreamParams);
201
+ const { ixs, tx } = await StreamClient.withdraw(withdrawStreamParams, solanaParams);
157
202
  } catch (exception) {
158
203
  // handle exception
159
204
  }
@@ -168,8 +213,18 @@ const topupStreamParams = {
168
213
  amount: getBN(100000000000, 9), // Specified amount to topup (increases deposited amount).
169
214
  };
170
215
 
216
+ const solanaParams = {
217
+ invoker: wallet, // Wallet/Keypair signing the transaction.
218
+ isNative: // [ONLY FOR wSOL STREAMS] [optional] Wether topup is with Native Solanas
219
+ };
220
+
221
+ const aptosParams = {
222
+ senderWallet: wallet, // AptosWalletAdapter Wallet of sender
223
+ tokenId: "0x1::aptos_coin::AptosCoin", // Aptos Coin type
224
+ };
225
+
171
226
  try {
172
- const { ixs, tx } = await StreamClient.topup(topupStreamParams);
227
+ const { ixs, tx } = await StreamClient.topup(topupStreamParams, solanaParams);
173
228
  } catch (exception) {
174
229
  // handle exception
175
230
  }
@@ -179,13 +234,22 @@ try {
179
234
 
180
235
  ```javascript
181
236
  const data = {
237
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",// Identifier of a stream to be transferred.
238
+ recipientId: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99", // New Recipient address
239
+ };
240
+
241
+ const solanaParams = {
182
242
  invoker: wallet, // Wallet/Keypair signing the transaction.
183
- id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
184
- recipientId: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99", // Identifier of a stream to be transferred.
185
243
  };
186
244
 
245
+ const aptosParams = {
246
+ senderWallet: wallet, // AptosWalletAdapter Wallet of sender
247
+ tokenId: "0x1::aptos_coin::AptosCoin", // Aptos Coin type
248
+ };
249
+
250
+
187
251
  try {
188
- const { tx } = await StreamClient.transfer(data);
252
+ const { tx } = await StreamClient.transfer(data, solanaParams);
189
253
  } catch (exception) {
190
254
  // handle exception
191
255
  }
@@ -195,12 +259,20 @@ try {
195
259
 
196
260
  ```javascript
197
261
  const cancelStreamParams = {
198
- invoker: wallet, // Wallet/Keypair signing the transaction.
199
262
  id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be canceled.
200
263
  };
201
264
 
265
+ const solanaParams = {
266
+ invoker: wallet, // Wallet/Keypair signing the transaction.
267
+ };
268
+
269
+ const aptosParams = {
270
+ senderWallet: wallet, // AptosWalletAdapter Wallet of sender
271
+ tokenId: "0x1::aptos_coin::AptosCoin", // Aptos Coin type
272
+ };
273
+
202
274
  try {
203
- const { ixs, tx } = await StreamClient.cancel(cancelStreamParams);
275
+ const { ixs, tx } = await StreamClient.cancel(cancelStreamParams, solanaParams);
204
276
  } catch (exception) {
205
277
  // handle exception
206
278
  }
@@ -210,15 +282,16 @@ try {
210
282
 
211
283
  ```javascript
212
284
  try {
213
- const stream = await StreamClient.getOne(
214
- "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA" // Identifier of a stream that is fetched.
215
- );
285
+ const stream = await StreamClient.getOne({
286
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA" // Identifier of a stream that is fetched.
287
+ });
216
288
  } catch (exception) {
217
289
  // handle exception
218
290
  }
219
291
  ```
220
292
 
221
293
  ## Get multiple streams for a specific wallet address
294
+ **NOTE: ONLY SUPPORTED FOR SOLANA CLIENT**
222
295
 
223
296
  ```javascript
224
297
  try {
@@ -234,11 +307,14 @@ try {
234
307
 
235
308
  ## Additional notes
236
309
 
237
- Default import `import Stream from '@streamflow/stream'` is an import of older SDK version that uses Anchor and doesn't support raw instructions, nor multi streams creation.
310
+ Streamflow protocol Solana program ID (devnet): `HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ`
311
+
312
+ Streamflow protocol Solana program ID (mainnet): `strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m`
313
+
314
+ Streamflow protocol Aptos program ID (testnet): `0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688`
238
315
 
239
- Streamflow protocol program ID (devnet): `HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ`
316
+ Streamflow protocol Aptos program ID (mainnet): `0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0`
240
317
 
241
- Streamflow protocol program ID (mainnet): `strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m`
242
318
 
243
319
  **All BN amounts are denominated in their smallest units.**
244
320
 
@@ -1,18 +1,46 @@
1
1
  import { BaseStreamClient } from "../common/BaseStreamClient";
2
- import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IWithdrawData } from "../common/types";
3
- import { ICreateStreamAptosExt, IMultiTransactionResult, ITransactionAptosExt, ITransactionResult } from "./types";
2
+ import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData } from "../common/types";
3
+ import { Contract, ICreateStreamAptosExt, IMultiTransactionResult, ITransactionAptosExt, ITransactionResult } from "./types";
4
4
  export default class AptosStreamClient extends BaseStreamClient {
5
5
  private programId;
6
6
  private maxGas;
7
7
  private client;
8
8
  constructor(clusterUrl: string, cluster?: ICluster, maxGas?: string, programId?: string);
9
+ /**
10
+ * Creates a new stream/vesting contract.
11
+ */
9
12
  create(streamData: ICreateStreamData, { senderWallet }: ICreateStreamAptosExt): Promise<ITransactionResult>;
13
+ /**
14
+ * Creates multiple stream/vesting contracts.
15
+ */
10
16
  createMultiple(multipleStreamData: ICreateMultipleStreamData, { senderWallet }: ICreateStreamAptosExt): Promise<IMultiTransactionResult>;
17
+ /**
18
+ * Attempts withdrawing from the specified stream.
19
+ */
11
20
  withdraw(withdrawData: IWithdrawData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
12
- cancel(cancelData: ICancelData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<any>;
13
- transfer(transferData: ITransferData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<any>;
14
- topup(topupData: ITopUpData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<any>;
15
- getOne({ id }: IGetOneData): Promise<any>;
21
+ /**
22
+ * Attempts canceling the specified stream.
23
+ */
24
+ cancel(cancelData: ICancelData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
25
+ /**
26
+ * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
27
+ */
28
+ transfer(transferData: ITransferData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
29
+ /**
30
+ * Tops up stream account with specified amount.
31
+ */
32
+ topup(topupData: ITopUpData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
33
+ /**
34
+ * Fetch stream data by its id (address).
35
+ */
36
+ getOne({ id }: IGetOneData): Promise<Contract>;
37
+ /**
38
+ * Attempts updating the stream auto withdrawal params and amount per period
39
+ */
40
+ update(updateData: IUpdateData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
41
+ /**
42
+ * Returns StreamClient protocol program ID.
43
+ */
16
44
  getProgramId(): string;
17
45
  getMaxGas(): {
18
46
  max_gas_amount: string;
@@ -67,6 +67,9 @@ var AptosStreamClient = /** @class */ (function (_super) {
67
67
  _this.client = new aptos_1.AptosClient(clusterUrl);
68
68
  return _this;
69
69
  }
70
+ /**
71
+ * Creates a new stream/vesting contract.
72
+ */
70
73
  AptosStreamClient.prototype.create = function (streamData, _a) {
71
74
  var senderWallet = _a.senderWallet;
72
75
  return __awaiter(this, void 0, void 0, function () {
@@ -108,6 +111,9 @@ var AptosStreamClient = /** @class */ (function (_super) {
108
111
  });
109
112
  });
110
113
  };
114
+ /**
115
+ * Creates multiple stream/vesting contracts.
116
+ */
111
117
  AptosStreamClient.prototype.createMultiple = function (multipleStreamData, _a) {
112
118
  var _b;
113
119
  var senderWallet = _a.senderWallet;
@@ -160,6 +166,9 @@ var AptosStreamClient = /** @class */ (function (_super) {
160
166
  });
161
167
  });
162
168
  };
169
+ /**
170
+ * Attempts withdrawing from the specified stream.
171
+ */
163
172
  AptosStreamClient.prototype.withdraw = function (withdrawData, _a) {
164
173
  var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
165
174
  return __awaiter(this, void 0, void 0, function () {
@@ -181,6 +190,9 @@ var AptosStreamClient = /** @class */ (function (_super) {
181
190
  });
182
191
  });
183
192
  };
193
+ /**
194
+ * Attempts canceling the specified stream.
195
+ */
184
196
  AptosStreamClient.prototype.cancel = function (cancelData, _a) {
185
197
  var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
186
198
  return __awaiter(this, void 0, void 0, function () {
@@ -202,6 +214,9 @@ var AptosStreamClient = /** @class */ (function (_super) {
202
214
  });
203
215
  });
204
216
  };
217
+ /**
218
+ * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
219
+ */
205
220
  AptosStreamClient.prototype.transfer = function (transferData, _a) {
206
221
  var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
207
222
  return __awaiter(this, void 0, void 0, function () {
@@ -223,6 +238,9 @@ var AptosStreamClient = /** @class */ (function (_super) {
223
238
  });
224
239
  });
225
240
  };
241
+ /**
242
+ * Tops up stream account with specified amount.
243
+ */
226
244
  AptosStreamClient.prototype.topup = function (topupData, _a) {
227
245
  var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
228
246
  return __awaiter(this, void 0, void 0, function () {
@@ -244,6 +262,9 @@ var AptosStreamClient = /** @class */ (function (_super) {
244
262
  });
245
263
  });
246
264
  };
265
+ /**
266
+ * Fetch stream data by its id (address).
267
+ */
247
268
  AptosStreamClient.prototype.getOne = function (_a) {
248
269
  var _b;
249
270
  var id = _a.id;
@@ -261,17 +282,50 @@ var AptosStreamClient = /** @class */ (function (_super) {
261
282
  tokenIdMatch = contract.type.match(/0x[0-9a-f]+::protocol::Contract<(.*)>/);
262
283
  tokenId = (_b = tokenIdMatch === null || tokenIdMatch === void 0 ? void 0 : tokenIdMatch[1]) !== null && _b !== void 0 ? _b : "";
263
284
  data = contract.data;
264
- return [2 /*return*/, [id, new types_2.Contract(data, tokenId)]];
285
+ return [2 /*return*/, new types_2.Contract(data, tokenId)];
265
286
  }
266
287
  });
267
288
  });
268
289
  };
290
+ /**
291
+ * Attempts updating the stream auto withdrawal params and amount per period
292
+ */
293
+ AptosStreamClient.prototype.update = function (updateData, _a) {
294
+ var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
295
+ return __awaiter(this, void 0, void 0, function () {
296
+ var payload, hash;
297
+ return __generator(this, function (_b) {
298
+ switch (_b.label) {
299
+ case 0:
300
+ payload = {
301
+ type: "update",
302
+ function: "".concat(this.programId, "::protocol::update"),
303
+ type_arguments: [tokenId],
304
+ arguments: [
305
+ updateData.id,
306
+ updateData.enableAutomaticWithdrawal ? [true] : [],
307
+ updateData.withdrawFrequency ? [updateData.withdrawFrequency.toString()] : [],
308
+ updateData.amountPerPeriod ? [updateData.amountPerPeriod.toString()] : [],
309
+ ],
310
+ };
311
+ return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
312
+ case 1:
313
+ hash = (_b.sent()).hash;
314
+ return [2 /*return*/, { txId: hash }];
315
+ }
316
+ });
317
+ });
318
+ };
319
+ /**
320
+ * Returns StreamClient protocol program ID.
321
+ */
269
322
  AptosStreamClient.prototype.getProgramId = function () {
270
323
  return this.programId;
271
324
  };
272
325
  AptosStreamClient.prototype.getMaxGas = function () {
273
326
  return { max_gas_amount: this.maxGas };
274
327
  };
328
+ // Utility function to prepare transaction payloads for multiple recipients.
275
329
  AptosStreamClient.prototype.generateMultiPayloads = function (multipleStreamData) {
276
330
  var _this = this;
277
331
  return multipleStreamData.recipients.map(function (recipient) {
@@ -1,10 +1,11 @@
1
- import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData } from "./types";
1
+ import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData, IUpdateData } from "./types";
2
2
  export declare abstract class BaseStreamClient {
3
- abstract create(streamData: ICreateStreamData, ...chainSpecificParams: any[]): Promise<any>;
4
- abstract createMultiple(multipleStreamData: ICreateMultipleStreamData, ...chainSpecificParams: any[]): Promise<any>;
5
- abstract withdraw(withdrawData: IWithdrawData, ...chainSpecificParams: any[]): Promise<any>;
6
- abstract cancel(cancelData: ICancelData, ...chainSpecificParams: any[]): Promise<any>;
7
- abstract transfer(transferData: ITransferData, ...chainSpecificParams: any[]): Promise<any>;
8
- abstract topup(topupData: ITopUpData, ...chainSpecificParams: any[]): Promise<any>;
9
- abstract getOne(getOneData: IGetOneData, ...chainSpecificParams: any[]): Promise<any>;
3
+ protected abstract create(streamData: ICreateStreamData, chainSpecificParams: any): Promise<any>;
4
+ protected abstract createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: any): Promise<any>;
5
+ protected abstract withdraw(withdrawData: IWithdrawData, chainSpecificParams: any): Promise<any>;
6
+ protected abstract cancel(cancelData: ICancelData, chainSpecificParams: any): Promise<any>;
7
+ protected abstract transfer(transferData: ITransferData, chainSpecificParams: any): Promise<any>;
8
+ protected abstract topup(topupData: ITopUpData, chainSpecificParams: any): Promise<any>;
9
+ protected abstract getOne(getOneData: IGetOneData, chainSpecificParams: any): Promise<any>;
10
+ protected abstract update(updateData: IUpdateData, chainSpecificParams: any): Promise<any>;
10
11
  }
@@ -2,9 +2,9 @@ import { Commitment, ConnectionConfig } from "@solana/web3.js";
2
2
  import SolanaStreamClient from "../solana/StreamClient";
3
3
  import AptosStreamClient from "../aptos/StreamClient";
4
4
  import { BaseStreamClient } from "./BaseStreamClient";
5
- import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IWithdrawData } from "./types";
6
- import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "../solana";
7
- import { ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos";
5
+ import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData } from "./types";
6
+ import { CreateMultiResponse, CreateResponse, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt, Stream, TxResponse } from "../solana";
7
+ import { ICreateStreamAptosExt, IMultiTransactionResult, ITransactionAptosExt, ITransactionResult } from "../aptos";
8
8
  export interface SolanaStreamClientOptions {
9
9
  chain: IChain.Solana;
10
10
  clusterUrl: string;
@@ -24,12 +24,37 @@ export default class GenericStreamClient extends BaseStreamClient {
24
24
  nativeStreamClient: SolanaStreamClient | AptosStreamClient;
25
25
  chain: IChain;
26
26
  constructor(options: GenericStreamClientOptions);
27
- create(streamData: ICreateStreamData, chainSpecificParams: ICreateStreamAptosExt | ICreateStreamSolanaExt): Promise<import("../solana").CreateResponse> | Promise<import("../aptos").ITransactionResult>;
28
- createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: ICreateStreamAptosExt | ICreateStreamSolanaExt): Promise<import("../solana").CreateMultiResponse> | Promise<import("../aptos").IMultiTransactionResult>;
29
- withdraw(withdrawData: IWithdrawData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<import("../solana").TxResponse> | Promise<import("../aptos").ITransactionResult>;
30
- cancel(cancelData: ICancelData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<any>;
31
- transfer(transferData: ITransferData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<any>;
32
- topup(topupData: ITopUpData, chainSpecificParams: ITransactionAptosExt | ITopUpStreamSolanaExt): Promise<any>;
33
- getOne(getOneData: IGetOneData): Promise<any>;
27
+ /**
28
+ * Creates a new stream/vesting contract.
29
+ */
30
+ create(streamData: ICreateStreamData, chainSpecificParams: ICreateStreamAptosExt | ICreateStreamSolanaExt): Promise<CreateResponse | ITransactionResult>;
31
+ /**
32
+ * Creates multiple stream/vesting contracts.
33
+ */
34
+ createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: ICreateStreamAptosExt | ICreateStreamSolanaExt): Promise<CreateMultiResponse | IMultiTransactionResult>;
35
+ /**
36
+ * Attempts withdrawing from the specified stream.
37
+ */
38
+ withdraw(withdrawData: IWithdrawData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<TxResponse | ITransactionResult>;
39
+ /**
40
+ * Attempts canceling the specified stream.
41
+ */
42
+ cancel(cancelData: ICancelData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<TxResponse | ITransactionResult>;
43
+ /**
44
+ * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
45
+ */
46
+ transfer(transferData: ITransferData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<TxResponse | ITransactionResult>;
47
+ /**
48
+ * Tops up stream account with specified amount.
49
+ */
50
+ topup(topupData: ITopUpData, chainSpecificParams: ITransactionAptosExt | ITopUpStreamSolanaExt): Promise<TxResponse | ITransactionResult>;
51
+ /**
52
+ * Fetch stream data by its id (address).
53
+ */
54
+ getOne(getOneData: IGetOneData): Promise<Stream>;
55
+ /**
56
+ * Attempts updating the stream auto withdrawal params and amount per period
57
+ */
58
+ update(updateData: IUpdateData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<TxResponse | ITransactionResult>;
34
59
  }
35
60
  export {};
@@ -35,6 +35,9 @@ var GenericStreamClient = /** @class */ (function (_super) {
35
35
  }
36
36
  return _this;
37
37
  }
38
+ /**
39
+ * Creates a new stream/vesting contract.
40
+ */
38
41
  GenericStreamClient.prototype.create = function (streamData, chainSpecificParams) {
39
42
  if (this.nativeStreamClient instanceof StreamClient_1.default) {
40
43
  var params = chainSpecificParams;
@@ -45,6 +48,9 @@ var GenericStreamClient = /** @class */ (function (_super) {
45
48
  return this.nativeStreamClient.create(streamData, params);
46
49
  }
47
50
  };
51
+ /**
52
+ * Creates multiple stream/vesting contracts.
53
+ */
48
54
  GenericStreamClient.prototype.createMultiple = function (multipleStreamData, chainSpecificParams) {
49
55
  if (this.nativeStreamClient instanceof StreamClient_1.default) {
50
56
  var params = chainSpecificParams;
@@ -55,6 +61,9 @@ var GenericStreamClient = /** @class */ (function (_super) {
55
61
  return this.nativeStreamClient.createMultiple(multipleStreamData, params);
56
62
  }
57
63
  };
64
+ /**
65
+ * Attempts withdrawing from the specified stream.
66
+ */
58
67
  GenericStreamClient.prototype.withdraw = function (withdrawData, chainSpecificParams) {
59
68
  if (this.nativeStreamClient instanceof StreamClient_1.default) {
60
69
  var params = chainSpecificParams;
@@ -65,6 +74,9 @@ var GenericStreamClient = /** @class */ (function (_super) {
65
74
  return this.nativeStreamClient.withdraw(withdrawData, params);
66
75
  }
67
76
  };
77
+ /**
78
+ * Attempts canceling the specified stream.
79
+ */
68
80
  GenericStreamClient.prototype.cancel = function (cancelData, chainSpecificParams) {
69
81
  if (this.nativeStreamClient instanceof StreamClient_1.default) {
70
82
  var params = chainSpecificParams;
@@ -75,6 +87,9 @@ var GenericStreamClient = /** @class */ (function (_super) {
75
87
  return this.nativeStreamClient.cancel(cancelData, params);
76
88
  }
77
89
  };
90
+ /**
91
+ * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
92
+ */
78
93
  GenericStreamClient.prototype.transfer = function (transferData, chainSpecificParams) {
79
94
  if (this.nativeStreamClient instanceof StreamClient_1.default) {
80
95
  var params = chainSpecificParams;
@@ -85,6 +100,9 @@ var GenericStreamClient = /** @class */ (function (_super) {
85
100
  return this.nativeStreamClient.transfer(transferData, params);
86
101
  }
87
102
  };
103
+ /**
104
+ * Tops up stream account with specified amount.
105
+ */
88
106
  GenericStreamClient.prototype.topup = function (topupData, chainSpecificParams) {
89
107
  if (this.nativeStreamClient instanceof StreamClient_1.default) {
90
108
  var params = chainSpecificParams;
@@ -95,9 +113,25 @@ var GenericStreamClient = /** @class */ (function (_super) {
95
113
  return this.nativeStreamClient.topup(topupData, params);
96
114
  }
97
115
  };
116
+ /**
117
+ * Fetch stream data by its id (address).
118
+ */
98
119
  GenericStreamClient.prototype.getOne = function (getOneData) {
99
120
  return this.nativeStreamClient.getOne(getOneData);
100
121
  };
122
+ /**
123
+ * Attempts updating the stream auto withdrawal params and amount per period
124
+ */
125
+ GenericStreamClient.prototype.update = function (updateData, chainSpecificParams) {
126
+ if (this.nativeStreamClient instanceof StreamClient_1.default) {
127
+ var params = chainSpecificParams;
128
+ return this.nativeStreamClient.update(updateData, params);
129
+ }
130
+ else {
131
+ var params = chainSpecificParams;
132
+ return this.nativeStreamClient.update(updateData, params);
133
+ }
134
+ };
101
135
  return GenericStreamClient;
102
136
  }(BaseStreamClient_1.BaseStreamClient));
103
137
  exports.default = GenericStreamClient;
@@ -29,6 +29,12 @@ export interface IWithdrawData {
29
29
  id: string;
30
30
  amount: BN;
31
31
  }
32
+ export interface IUpdateData {
33
+ id: string;
34
+ enableAutomaticWithdrawal?: boolean;
35
+ withdrawFrequency?: BN;
36
+ amountPerPeriod?: BN;
37
+ }
32
38
  export interface ICancelData {
33
39
  id: string;
34
40
  }
@@ -1,6 +1,6 @@
1
1
  import { Connection, Commitment, ConnectionConfig } from "@solana/web3.js";
2
2
  import { Stream as StreamData, GetAllParams, CreateResponse, CreateMultiResponse, TxResponse, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "./types";
3
- import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IWithdrawData } from "../common/types";
3
+ import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData } from "../common/types";
4
4
  import { BaseStreamClient } from "../common/BaseStreamClient";
5
5
  export default class SolanaStreamClient extends BaseStreamClient {
6
6
  private connection;
@@ -15,26 +15,6 @@ export default class SolanaStreamClient extends BaseStreamClient {
15
15
  /**
16
16
  * Creates a new stream/vesting contract.
17
17
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
18
- * @param {CreateParams} data
19
- * @param {WalletAdapter | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
20
- * @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
21
- * @param {string} data.mint - SPL Token mint.
22
- * @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
23
- * @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
24
- * @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
25
- * @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
26
- * @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
27
- * @param {BN} data.amountPerPeriod - Amount unlocked per each period.
28
- * @param {string} data.name - Stream name/subject.
29
- * @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
30
- * @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
31
- * @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
32
- * @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
33
- * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
34
- * @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
35
- * @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.
36
- * @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
37
- * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
38
18
  */
39
19
  create({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, }: ICreateStreamData, { sender, partner, isNative }: ICreateStreamSolanaExt): Promise<CreateResponse>;
40
20
  /**
@@ -46,101 +26,46 @@ export default class SolanaStreamClient extends BaseStreamClient {
46
26
  * - initialized contract PDA off chain
47
27
  *
48
28
  * If you are not sure if you should use create or create_unchecked, go for create to be safer.
49
- *
50
- * @param {CreateParams} data
51
- * @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
52
- * @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
53
- * @param {string} data.mint - SPL Token mint.
54
- * @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
55
- * @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
56
- * @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
57
- * @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
58
- * @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
59
- * @param {BN} data.amountPerPeriod - Amount unlocked per each period.
60
- * @param {string} data.name - Stream name/subject.
61
- * @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
62
- * @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
63
- * @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
64
- * @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
65
- * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
66
- * @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
67
- * @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.
68
- * @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
69
- * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
70
29
  */
71
30
  createUnchecked({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, }: ICreateStreamData, { sender, partner, isNative }: ICreateStreamSolanaExt): Promise<CreateResponse>;
72
31
  /**
73
- * Creates a new stream/vesting contract.
32
+ * Creates multiple stream/vesting contracts.
74
33
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
75
- * @param {CreateMultiParams} data
76
- * @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
77
- * @param {MultiRecipient[]} data.recipientsData
78
- * @param {string} data.mint - SPL Token mint.
79
- * @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
80
- * @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
81
- * @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
82
- * @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
83
- * @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
84
- * @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
85
- * @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
86
- * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
87
- * @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
88
- * @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.
89
- * @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
90
- * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
91
34
  */
92
35
  createMultiple(data: ICreateMultipleStreamData, { sender, partner, isNative }: ICreateStreamSolanaExt): Promise<CreateMultiResponse>;
93
36
  /**
94
- * Attempts withdrawal from the specified stream.
95
- * @param {WithdrawParams} data
96
- * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (recipient) or transaction will fail.
97
- * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be withdrawn from.
98
- * @param {BN} data.amount - Requested amount (in the smallest units) to withdraw (while streaming). If stream is completed, the whole amount will be withdrawn.
37
+ * Attempts withdrawing from the specified stream.
99
38
  */
100
39
  withdraw({ id, amount }: IWithdrawData, { invoker }: IInteractStreamSolanaExt): Promise<TxResponse>;
101
40
  /**
102
41
  * Attempts canceling the specified stream.
103
- * @param {CancelParams} data
104
- * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
105
- * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be canceled.
106
42
  */
107
43
  cancel({ id }: ICancelData, { invoker }: IInteractStreamSolanaExt): Promise<TxResponse>;
108
44
  /**
109
45
  * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
110
46
  * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
111
- * @param {TransferParams} data
112
- * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
113
- * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be transferred.
114
- * @param {string} data.recipientId - Address of a new recipient.
115
47
  */
116
48
  transfer({ id, newRecipient: newRecipientString }: ITransferData, { invoker }: IInteractStreamSolanaExt): Promise<TxResponse>;
117
49
  /**
118
- * Tops up stream account deposited amount.
119
- * @param {TopupParams} data
120
- * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match current stream sender or transaction will fail.
121
- * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be topped up.
122
- * @param {BN} data.amount - Specified amount (in the smallest units) to topup (increases deposited amount).
50
+ * Tops up stream account with specified amount.
123
51
  */
124
52
  topup({ id, amount }: ITopUpData, { invoker, isNative }: ITopUpStreamSolanaExt): Promise<TxResponse>;
125
53
  /**
126
54
  * Fetch stream data by its id (address).
127
- * @param {string} id - Identifier of a stream that is fetched.
128
55
  */
129
56
  getOne({ id }: IGetOneData): Promise<StreamData>;
130
57
  /**
131
58
  * Fetch streams/contracts by providing direction.
132
59
  * Streams are sorted by start time in ascending order.
133
- * @param {GetAllParams} data
134
- * @param {PublicKey} data.wallet - PublicKey of the wallet for which the streams/contracts are fetched.
135
- * @param {StreamType} [data.type = StreamType.All] - It can be one of: stream, vesting, all.
136
- * @param {StreamDirection} [data.direction = StreamDirection.All] - It can be one of: incoming, outgoing, all.
137
60
  */
138
61
  get({ wallet, type, direction, }: GetAllParams): Promise<[string, StreamData][]>;
139
62
  private sign;
63
+ /**
64
+ * Attempts updating the stream auto withdrawal params and amount per period
65
+ */
66
+ update(data: IUpdateData, { invoker }: IInteractStreamSolanaExt): Promise<TxResponse>;
140
67
  /**
141
68
  * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
142
- * @param {MultiRecipient} recipient - Wallet sending stream to
143
- * @param {CreateMultiParams} streamParams - Parameters of stream user wants to create.
144
69
  */
145
70
  private prepareStreamTransaction;
146
71
  }
@@ -139,26 +139,6 @@ var SolanaStreamClient = /** @class */ (function (_super) {
139
139
  /**
140
140
  * Creates a new stream/vesting contract.
141
141
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
142
- * @param {CreateParams} data
143
- * @param {WalletAdapter | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
144
- * @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
145
- * @param {string} data.mint - SPL Token mint.
146
- * @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
147
- * @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
148
- * @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
149
- * @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
150
- * @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
151
- * @param {BN} data.amountPerPeriod - Amount unlocked per each period.
152
- * @param {string} data.name - Stream name/subject.
153
- * @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
154
- * @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
155
- * @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
156
- * @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
157
- * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
158
- * @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
159
- * @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.
160
- * @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
161
- * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
162
142
  */
163
143
  SolanaStreamClient.prototype.create = function (_a, _b) {
164
144
  var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d;
@@ -264,27 +244,6 @@ var SolanaStreamClient = /** @class */ (function (_super) {
264
244
  * - initialized contract PDA off chain
265
245
  *
266
246
  * If you are not sure if you should use create or create_unchecked, go for create to be safer.
267
- *
268
- * @param {CreateParams} data
269
- * @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
270
- * @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
271
- * @param {string} data.mint - SPL Token mint.
272
- * @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
273
- * @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
274
- * @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
275
- * @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
276
- * @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
277
- * @param {BN} data.amountPerPeriod - Amount unlocked per each period.
278
- * @param {string} data.name - Stream name/subject.
279
- * @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
280
- * @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
281
- * @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
282
- * @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
283
- * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
284
- * @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
285
- * @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.
286
- * @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
287
- * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
288
247
  */
289
248
  SolanaStreamClient.prototype.createUnchecked = function (_a, _b) {
290
249
  var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d;
@@ -378,24 +337,8 @@ var SolanaStreamClient = /** @class */ (function (_super) {
378
337
  });
379
338
  };
380
339
  /**
381
- * Creates a new stream/vesting contract.
340
+ * Creates multiple stream/vesting contracts.
382
341
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
383
- * @param {CreateMultiParams} data
384
- * @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
385
- * @param {MultiRecipient[]} data.recipientsData
386
- * @param {string} data.mint - SPL Token mint.
387
- * @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
388
- * @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
389
- * @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
390
- * @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
391
- * @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
392
- * @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
393
- * @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
394
- * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
395
- * @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
396
- * @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.
397
- * @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
398
- * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
399
342
  */
400
343
  SolanaStreamClient.prototype.createMultiple = function (data, _a) {
401
344
  var sender = _a.sender, _b = _a.partner, partner = _b === void 0 ? null : _b, _c = _a.isNative, isNative = _c === void 0 ? false : _c;
@@ -495,11 +438,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
495
438
  });
496
439
  };
497
440
  /**
498
- * Attempts withdrawal from the specified stream.
499
- * @param {WithdrawParams} data
500
- * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (recipient) or transaction will fail.
501
- * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be withdrawn from.
502
- * @param {BN} data.amount - Requested amount (in the smallest units) to withdraw (while streaming). If stream is completed, the whole amount will be withdrawn.
441
+ * Attempts withdrawing from the specified stream.
503
442
  */
504
443
  SolanaStreamClient.prototype.withdraw = function (_a, _b) {
505
444
  var id = _a.id, amount = _a.amount;
@@ -560,9 +499,6 @@ var SolanaStreamClient = /** @class */ (function (_super) {
560
499
  };
561
500
  /**
562
501
  * Attempts canceling the specified stream.
563
- * @param {CancelParams} data
564
- * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
565
- * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be canceled.
566
502
  */
567
503
  SolanaStreamClient.prototype.cancel = function (_a, _b) {
568
504
  var id = _a.id;
@@ -626,10 +562,6 @@ var SolanaStreamClient = /** @class */ (function (_super) {
626
562
  /**
627
563
  * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
628
564
  * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
629
- * @param {TransferParams} data
630
- * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
631
- * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be transferred.
632
- * @param {string} data.recipientId - Address of a new recipient.
633
565
  */
634
566
  SolanaStreamClient.prototype.transfer = function (_a, _b) {
635
567
  var id = _a.id, newRecipientString = _a.newRecipient;
@@ -685,11 +617,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
685
617
  });
686
618
  };
687
619
  /**
688
- * Tops up stream account deposited amount.
689
- * @param {TopupParams} data
690
- * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match current stream sender or transaction will fail.
691
- * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be topped up.
692
- * @param {BN} data.amount - Specified amount (in the smallest units) to topup (increases deposited amount).
620
+ * Tops up stream account with specified amount.
693
621
  */
694
622
  SolanaStreamClient.prototype.topup = function (_a, _b) {
695
623
  var id = _a.id, amount = _a.amount;
@@ -761,7 +689,6 @@ var SolanaStreamClient = /** @class */ (function (_super) {
761
689
  };
762
690
  /**
763
691
  * Fetch stream data by its id (address).
764
- * @param {string} id - Identifier of a stream that is fetched.
765
692
  */
766
693
  SolanaStreamClient.prototype.getOne = function (_a) {
767
694
  var id = _a.id;
@@ -783,10 +710,6 @@ var SolanaStreamClient = /** @class */ (function (_super) {
783
710
  /**
784
711
  * Fetch streams/contracts by providing direction.
785
712
  * Streams are sorted by start time in ascending order.
786
- * @param {GetAllParams} data
787
- * @param {PublicKey} data.wallet - PublicKey of the wallet for which the streams/contracts are fetched.
788
- * @param {StreamType} [data.type = StreamType.All] - It can be one of: stream, vesting, all.
789
- * @param {StreamDirection} [data.direction = StreamDirection.All] - It can be one of: incoming, outgoing, all.
790
713
  */
791
714
  SolanaStreamClient.prototype.get = function (_a) {
792
715
  var wallet = _a.wallet, _b = _a.type, type = _b === void 0 ? types_2.StreamType.All : _b, _c = _a.direction, direction = _c === void 0 ? types_2.StreamDirection.All : _c;
@@ -863,10 +786,53 @@ var SolanaStreamClient = /** @class */ (function (_super) {
863
786
  });
864
787
  });
865
788
  };
789
+ /**
790
+ * Attempts updating the stream auto withdrawal params and amount per period
791
+ */
792
+ SolanaStreamClient.prototype.update = function (data, _a) {
793
+ var invoker = _a.invoker;
794
+ return __awaiter(this, void 0, void 0, function () {
795
+ var ixs, streamPublicKey, escrow, commitment, hash, tx, signature;
796
+ var _b;
797
+ return __generator(this, function (_c) {
798
+ switch (_c.label) {
799
+ case 0:
800
+ if (!invoker.publicKey) {
801
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
802
+ }
803
+ ixs = [];
804
+ streamPublicKey = new web3_js_1.PublicKey(data.id);
805
+ return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
806
+ case 1:
807
+ escrow = _c.sent();
808
+ if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
809
+ throw new Error("Couldn't get account info");
810
+ }
811
+ ixs.push((0, instructions_1.updateStreamInstruction)(data, this.programId, {
812
+ authority: invoker.publicKey,
813
+ metadata: streamPublicKey,
814
+ withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
815
+ systemProgram: web3_js_1.SystemProgram.programId,
816
+ }));
817
+ commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
818
+ return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
819
+ case 2:
820
+ hash = _c.sent();
821
+ tx = (_b = new web3_js_1.Transaction({
822
+ feePayer: invoker.publicKey,
823
+ blockhash: hash.blockhash,
824
+ lastValidBlockHeight: hash.lastValidBlockHeight,
825
+ })).add.apply(_b, __spreadArray([], __read(ixs), false));
826
+ return [4 /*yield*/, this.sign(invoker, tx, hash)];
827
+ case 3:
828
+ signature = _c.sent();
829
+ return [2 /*return*/, { ixs: ixs, tx: signature }];
830
+ }
831
+ });
832
+ });
833
+ };
866
834
  /**
867
835
  * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
868
- * @param {MultiRecipient} recipient - Wallet sending stream to
869
- * @param {CreateMultiParams} streamParams - Parameters of stream user wants to create.
870
836
  */
871
837
  SolanaStreamClient.prototype.prepareStreamTransaction = function (recipient, streamParams, solanaExtendedConfig) {
872
838
  return __awaiter(this, void 0, void 0, function () {
@@ -76,6 +76,11 @@ export interface ICreateUncheckedStreamLayout {
76
76
  export interface IWithdrawStreamLayout {
77
77
  amount: Uint8Array;
78
78
  }
79
+ export interface IUpdateStreamLayout {
80
+ enable_automatic_withdrawal?: number;
81
+ withdraw_frequency?: Uint8Array;
82
+ amount_per_period?: Uint8Array;
83
+ }
79
84
  export interface ITopupStreamLayout {
80
85
  amount: Uint8Array;
81
86
  }
@@ -1,5 +1,6 @@
1
1
  import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
2
2
  import BN from "bn.js";
3
+ import { IUpdateData } from "../common/types";
3
4
  interface CreateStreamData {
4
5
  start: BN;
5
6
  depositedAmount: BN;
@@ -84,6 +85,13 @@ interface WithdrawAccounts {
84
85
  tokenProgram: PublicKey;
85
86
  }
86
87
  export declare const withdrawStreamInstruction: (amount: BN, programId: PublicKey, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }: WithdrawAccounts) => TransactionInstruction;
88
+ interface UpdateAccounts {
89
+ authority: PublicKey;
90
+ metadata: PublicKey;
91
+ withdrawor: PublicKey;
92
+ systemProgram: PublicKey;
93
+ }
94
+ export declare const updateStreamInstruction: (params: IUpdateData, programId: PublicKey, { authority, metadata, withdrawor, systemProgram }: UpdateAccounts) => TransactionInstruction;
87
95
  interface CancelAccounts {
88
96
  authority: PublicKey;
89
97
  sender: PublicKey;
@@ -87,7 +87,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
87
87
  return (mod && mod.__esModule) ? mod : { "default": mod };
88
88
  };
89
89
  Object.defineProperty(exports, "__esModule", { value: true });
90
- exports.prepareWrappedAccount = exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
90
+ exports.prepareWrappedAccount = exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.updateStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
91
91
  var buffer_1 = require("buffer");
92
92
  var web3_js_1 = require("@solana/web3.js");
93
93
  var bn_js_1 = __importDefault(require("bn.js"));
@@ -253,6 +253,35 @@ var withdrawStreamInstruction = function (amount, programId, _a) {
253
253
  });
254
254
  };
255
255
  exports.withdrawStreamInstruction = withdrawStreamInstruction;
256
+ var updateStreamInstruction = function (params, programId, _a) {
257
+ var _b, _c;
258
+ var authority = _a.authority, metadata = _a.metadata, withdrawor = _a.withdrawor, systemProgram = _a.systemProgram;
259
+ var keys = [
260
+ { pubkey: authority, isSigner: true, isWritable: true },
261
+ { pubkey: metadata, isSigner: false, isWritable: true },
262
+ { pubkey: withdrawor, isSigner: false, isWritable: true },
263
+ { pubkey: systemProgram, isSigner: false, isWritable: false },
264
+ ];
265
+ var data = buffer_1.Buffer.alloc(100);
266
+ var decodedData = {
267
+ enable_automatic_withdrawal: Number(params.enableAutomaticWithdrawal),
268
+ withdraw_frequency: (_b = params.withdrawFrequency) === null || _b === void 0 ? void 0 : _b.toArrayLike(buffer_1.Buffer, "le", 8),
269
+ amount_per_period: (_c = params.amountPerPeriod) === null || _c === void 0 ? void 0 : _c.toArrayLike(buffer_1.Buffer, "le", 8),
270
+ };
271
+ var encodeLength = Layout.encodeUpdateStream(decodedData, data);
272
+ data = data.slice(0, encodeLength);
273
+ data = buffer_1.Buffer.concat([
274
+ buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:update")).slice(0, 8),
275
+ data,
276
+ buffer_1.Buffer.alloc(20),
277
+ ]);
278
+ return new web3_js_1.TransactionInstruction({
279
+ keys: keys,
280
+ programId: programId,
281
+ data: data,
282
+ });
283
+ };
284
+ exports.updateStreamInstruction = updateStreamInstruction;
256
285
  var cancelStreamInstruction = function (programId, _a) {
257
286
  var authority = _a.authority, sender = _a.sender, senderTokens = _a.senderTokens, recipient = _a.recipient, recipientTokens = _a.recipientTokens, metadata = _a.metadata, escrowTokens = _a.escrowTokens, streamflowTreasury = _a.streamflowTreasury, streamflowTreasuryTokens = _a.streamflowTreasuryTokens, partner = _a.partner, partnerTokens = _a.partnerTokens, mint = _a.mint, tokenProgram = _a.tokenProgram;
258
287
  var keys = [
@@ -1,5 +1,6 @@
1
+ /// <reference types="node" />
1
2
  import * as BufferLayout from "@solana/buffer-layout";
2
- import { ICreateStreamLayout, ICreateUncheckedStreamLayout, IStreamLayout, ITopupStreamLayout, IWithdrawStreamLayout } from "./instructionTypes";
3
+ import { ICreateStreamLayout, ICreateUncheckedStreamLayout, IStreamLayout, ITopupStreamLayout, IUpdateStreamLayout, IWithdrawStreamLayout } from "./instructionTypes";
3
4
  /**
4
5
  * Stream layout
5
6
  */
@@ -16,6 +17,10 @@ export declare const createUncheckedStreamLayout: BufferLayout.Structure<ICreate
16
17
  * Withdraw stream instruction layout
17
18
  */
18
19
  export declare const withdrawStreamLayout: BufferLayout.Structure<IWithdrawStreamLayout>;
20
+ /**
21
+ * Encode stream instruction layout
22
+ */
23
+ export declare const encodeUpdateStream: (values: IUpdateStreamLayout, data: Buffer) => number;
19
24
  /**
20
25
  * Topup stream instruction layout
21
26
  */
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.topupStreamLayout = exports.withdrawStreamLayout = exports.createUncheckedStreamLayout = exports.createStreamLayout = exports.streamLayout = void 0;
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
28
  /**
29
29
  * Stream layout
@@ -113,6 +113,43 @@ exports.createUncheckedStreamLayout = BufferLayout.struct([
113
113
  * Withdraw stream instruction layout
114
114
  */
115
115
  exports.withdrawStreamLayout = BufferLayout.struct([BufferLayout.blob(8, "amount")]);
116
+ /**
117
+ * Encode stream instruction layout
118
+ */
119
+ var encodeUpdateStream = function (values, data) {
120
+ var _a, _b, _c;
121
+ var structs = [];
122
+ if (values.enable_automatic_withdrawal) {
123
+ structs.push(BufferLayout.u8("enable_automatic_withdrawal_exists"));
124
+ structs.push(BufferLayout.u8("enable_automatic_withdrawal"));
125
+ }
126
+ else {
127
+ structs.push(BufferLayout.u8("enable_automatic_withdrawal_exists"));
128
+ }
129
+ if (values.withdraw_frequency) {
130
+ structs.push(BufferLayout.u8("withdraw_frequency_exists"));
131
+ structs.push(BufferLayout.blob(8, "withdraw_frequency"));
132
+ }
133
+ else {
134
+ structs.push(BufferLayout.u8("withdraw_frequency_exists"));
135
+ }
136
+ if (values.amount_per_period) {
137
+ structs.push(BufferLayout.u8("amount_per_period_exists"));
138
+ structs.push(BufferLayout.blob(8, "amount_per_period"));
139
+ }
140
+ else {
141
+ structs.push(BufferLayout.u8("amount_per_period_exists"));
142
+ }
143
+ return BufferLayout.struct(structs).encode({
144
+ enable_automatic_withdrawal_exists: values.enable_automatic_withdrawal ? 1 : 0,
145
+ enable_automatic_withdrawal: (_a = values.enable_automatic_withdrawal) !== null && _a !== void 0 ? _a : 0,
146
+ withdraw_frequency_exists: values.withdraw_frequency ? 1 : 0,
147
+ withdraw_frequency: (_b = values.withdraw_frequency) !== null && _b !== void 0 ? _b : new Uint8Array(),
148
+ amount_per_period_exists: values.amount_per_period ? 1 : 0,
149
+ amount_per_period: (_c = values.amount_per_period) !== null && _c !== void 0 ? _c : new Uint8Array(),
150
+ }, data);
151
+ };
152
+ exports.encodeUpdateStream = encodeUpdateStream;
116
153
  /**
117
154
  * Topup stream instruction layout
118
155
  */
@@ -250,7 +250,7 @@ function sendAndConfirmStreamRawTransaction(connection, batchItem) {
250
250
  return [2 /*return*/, __assign(__assign({}, batchItem), { signature: completedTxSignature })];
251
251
  case 2:
252
252
  error_1 = _b.sent();
253
- throw { recipient: batchItem.recipient, error: error_1 };
253
+ throw { recipient: batchItem.recipient, error: error_1.toString() };
254
254
  case 3: return [2 /*return*/];
255
255
  }
256
256
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "4.0.0-Alpha.3",
3
+ "version": "4.0.0",
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/",