@streamflow/stream 2.2.2 → 3.0.0-test.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,3 @@
1
- **Important: Security audit for the v2 is underway.**
2
-
3
1
  Docs: https://streamflow.finance/js-sdk/
4
2
 
5
3
  # Streamflow
@@ -8,88 +6,136 @@ Streamflow is a token distribution platform powered by a streaming payments' pro
8
6
 
9
7
  There are several ways to use **Streamflow**:
10
8
 
11
- - **(easiest) [app.streamflow.finance](https://app.streamflow.finance)** (React application that uses JS SDK directly)
12
- - **[JS SDK](https://github.com/streamflow-finance/js-sdk)** to interact with the protocol => [NPM package](https://www.npmjs.com/package/@streamflow/stream/v/2.0.0)
9
+ - **(easiest) [app.streamflow.finance](https://app.streamflow.finance?utm_medium=github.com&utm_source=referral&utm_campaign=js-sdk-repo)** (React application that uses JS SDK directly)
10
+ - **[JS SDK](https://github.com/streamflow-finance/js-sdk)** to interact with the protocol => [NPM package](https://www.npmjs.com/package/@streamflow/stream)
13
11
  - **[Rust SDK](https://github.com/streamflow-finance/rust-sdk)** to integrate within a Solana program => [Rust Crate](https://docs.rs/streamflow-sdk/)
14
12
 
15
- ## JS SDK
13
+ **Security audit passed ✅**
14
+
15
+ Protocol audit available [here](https://github.com/streamflow-finance/rust-sdk/blob/main/protocol_audit.pdf).
16
+ Partner oracle audit available here [here](https://github.com/streamflow-finance/rust-sdk/blob/main/partner_oracle_audit.pdf).
17
+
18
+ ## JS SDK to interact with Streamflow protocol.
16
19
 
17
- This SDK allows you to `create`, `withdraw`, `cancel`, `topup` and `transfer` SPL token stream.
20
+ This package allows you to `create`, `createMultiple`, `withdraw`, `cancel`, `topup` and `transfer` SPL token stream.
18
21
 
19
22
  You can also `getOne` stream and `get` multiple streams.
20
23
 
21
24
  ---
22
25
 
23
- ### Installation
26
+ ## Installation
24
27
 
25
28
  `npm i @streamflow/stream @solana/web3.js @project-serum/anchor`
26
29
 
27
30
  > _Anchor is needed for the `Wallet` type. We plan on removing this dependency in upcoming releases._
28
31
 
29
- `bn.js` library is used for handling big numbers.
32
+ ## Import SDK
33
+
34
+ Most common imports:
30
35
 
31
36
  ```javascript
32
- import { Connection } from "@solana/web3.js";
33
- import { Wallet } from "@project-serum/anchor/src/provider";
34
- import BN from "bn.js";
37
+ 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,
53
+ getBN,
54
+ getNumberFromBN,
55
+ } from "@streamflow/stream";
35
56
  ```
36
57
 
37
- ### Usage
58
+ _Check the SDK for other types and utility functions._
38
59
 
39
- #### Imports
60
+ ## Create StreamClient instance
40
61
 
41
- Most common imports:
62
+ Before creating and manipulating streams StreamClient instance must be created.
63
+ All streams functions are methods on this instance.
42
64
 
43
65
  ```javascript
44
- import Stream, {
45
- Stream,
46
- CreateStreamParams,
47
- WithdrawStreamParams,
48
- TransferStreamParams,
49
- TopupStreamParams,
50
- CancelStreamParams,
51
- GetStreamParams,
52
- GetStreamsParams,
53
- StreamDirection,
54
- StreamType,
55
- Cluster,
56
- TransactionResponse,
57
- CreateStreamResponse,
58
- } from "@streamflow/stream";
59
- ```
66
+ import { StreamClient } from "@streamflow/stream";
60
67
 
61
- _Check the SDK for other types and utility functions._
68
+ const StreamClient = new StreamClient(
69
+ "https://api.mainnet-beta.solana.com",
70
+ Cluster.Mainnet,
71
+ "confirmed"
72
+ );
73
+ ```
62
74
 
63
- #### Create stream
75
+ ## Create stream
64
76
 
65
77
  ```javascript
66
78
  const createStreamParams = {
67
- connection: connection, // Connection to the cluster.
68
- sender: wallet, // Wallet signing the transaction, creating and sending the stream.
69
- recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Solana recipient address.
70
- mint: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // SPL Token mint.
71
- start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
72
- depositedAmount: new BN(1000000000000), // Deposited amount of tokens (using smallest denomination).
73
- period: 1, // Time step (period) in seconds per which the unlocking occurs.
74
- cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds.
75
- cliffAmount: new BN(100000000000), // Amount (smallest denomination) unlocked at the "cliff" timestamp.
76
- amountPerPeriod: new BN(5000000000), // Release rate: how many tokens are unlocked per each period.
77
- name: "Transfer to Jane Doe.", // The stream name or subject.
78
- canTopup: false, // setting to FALSE will effectively create a vesting contract.
79
- cancelableBySender: true, // Whether or not sender can cancel the stream.
80
- cancelableByRecipient: false, // Whether or not recipient can cancel the stream.
81
- transferableBySender: true, // Whether or not sender can transfer the stream to the new recipient.
82
- transferableByRecipient: false, // Whether or not recipient can transfer the stream to the new recipient.
83
- automaticWithdrawal: true, // [WIP] Whether or not a 3rd party (e.g. cron job, "cranker") can initiate a token withdraw/transfer. Defaults to false.
84
- 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.
85
- partner: "AAAAA075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // (optional) Partner's wallet address (string).
86
- cluster: Cluster.Mainnet, // (optional) Cluster (default is Cluster.Mainnet).
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.
85
+ 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.
88
+ name: "Transfer to Jane Doe.", // The stream name or subject.
89
+ 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).
87
97
  };
88
98
 
89
99
  try {
90
- const { tx, id } = await Stream.create(createStreamParams);
100
+ const { ixs, tx, metadata } = await StreamClient.create(createStreamParams);
91
101
  } catch (exception) {
92
- // handle exception
102
+ // handle exception
103
+ }
104
+ ```
105
+
106
+ ## Create multiple streams at once
107
+
108
+ ```javascript
109
+ const recipients = [
110
+ {
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.
114
+ },
115
+ ];
116
+
117
+ 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.
123
+ 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).
133
+ };
134
+
135
+ try {
136
+ const { txs } = await StreamClient.createMultiple(createMultiStreamsParams);
137
+ } catch (exception) {
138
+ // handle exception
93
139
  }
94
140
  ```
95
141
 
@@ -97,110 +143,101 @@ try {
97
143
 
98
144
  Please note that transaction fees for the scheduled transfers are paid upfront by the stream creator (sender).\_
99
145
 
100
- #### Withdraw from stream
146
+ ## Withdraw from stream
101
147
 
102
148
  ```javascript
103
149
  const withdrawStreamParams = {
104
- connection: connection, // Connection to the cluster.
105
- invoker: wallet, // Wallet signing the transaction.
106
- id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be withdrawn from.
107
- amount: new BN(100000000000), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
108
- cluster: Cluster.Mainnet, // Cluster (optional, default is Cluster.Mainnet).
150
+ invoker: wallet, // Wallet/Keypair signing the transaction.
151
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be withdrawn from.
152
+ amount: getBN(100000000000, 9), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
109
153
  };
110
154
 
111
155
  try {
112
- const { tx } = await Stream.withdraw(withdrawStreamParams);
156
+ const { ixs, tx } = await StreamClient.withdraw(withdrawStreamParams);
113
157
  } catch (exception) {
114
- // handle exception
158
+ // handle exception
115
159
  }
116
160
  ```
117
161
 
118
- #### Topup stream
162
+ ## Topup stream
119
163
 
120
164
  ```javascript
121
165
  const topupStreamParams = {
122
- connection: connection, // Connection to the cluster.
123
- invoker: wallet, // Wallet signing the transaction.
124
- id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be topped up.
125
- amount: new BN(100000000000), // Specified amount to topup (increases deposited amount).
126
- cluster: Cluster.Mainnet, // Cluster (optional, default is Cluster.Mainnet).
166
+ invoker: wallet, // Wallet/Keypair signing the transaction.
167
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be topped up.
168
+ amount: getBN(100000000000, 9), // Specified amount to topup (increases deposited amount).
127
169
  };
128
170
 
129
171
  try {
130
- const { tx } = await Stream.topup(topupStreamParams);
172
+ const { ixs, tx } = await StreamClient.topup(topupStreamParams);
131
173
  } catch (exception) {
132
- // handle exception
174
+ // handle exception
133
175
  }
134
176
  ```
135
177
 
136
- #### Transfer stream to another recipient
178
+ ## Transfer stream to another recipient
137
179
 
138
180
  ```javascript
139
181
  const data = {
140
- connection: connection, // Connection to the cluster.
141
- invoker: wallet, // Wallet signing the transaction.
142
- id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
143
- recipientId: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99", // Identifier of a stream to be transferred.
144
- cluster: Cluster.Mainnet, // Cluster (optional, default is Cluster.Mainnet).
182
+ invoker: wallet, // Wallet/Keypair signing the transaction.
183
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
184
+ recipientId: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99", // Identifier of a stream to be transferred.
145
185
  };
146
186
 
147
187
  try {
148
- const { tx } = await Stream.transfer(data);
188
+ const { tx } = await StreamClient.transfer(data);
149
189
  } catch (exception) {
150
- // handle exception
190
+ // handle exception
151
191
  }
152
192
  ```
153
193
 
154
- #### Cancel stream
194
+ ## Cancel stream
155
195
 
156
196
  ```javascript
157
197
  const cancelStreamParams = {
158
- connection: connection, // Connection to the cluster.
159
- invoker: wallet, // Wallet signing the transaction.
160
- id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be canceled.
161
- cluster: Cluster.Mainnet, // Cluster (optional, default is Cluster.Mainnet).
198
+ invoker: wallet, // Wallet/Keypair signing the transaction.
199
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be canceled.
162
200
  };
163
201
 
164
202
  try {
165
- const { tx } = await Stream.cancel(cancelStreamParams);
203
+ const { ixs, tx } = await StreamClient.cancel(cancelStreamParams);
166
204
  } catch (exception) {
167
- // handle exception
205
+ // handle exception
168
206
  }
169
207
  ```
170
208
 
171
- #### Get one stream by its ID
209
+ ## Get one stream by its ID
172
210
 
173
211
  ```javascript
174
212
  try {
175
- const stream = await Stream.getOne({
176
- connection: connection, // Connection to the cluster.
177
- id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream that is fetched.
178
- });
213
+ const stream = await StreamClient.getOne(
214
+ "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA" // Identifier of a stream that is fetched.
215
+ );
179
216
  } catch (exception) {
180
- // handle exception
217
+ // handle exception
181
218
  }
182
219
  ```
183
220
 
184
- #### Get multiple streams for a specific wallet address
221
+ ## Get multiple streams for a specific wallet address
185
222
 
186
223
  ```javascript
187
224
  try {
188
- const streams = Stream.get({
189
- connection: connection, // Connection to the cluster.
190
- wallet: wallet, // Wallet signing the transaction.
191
- type: StreamType.All, // (optional) Type, default is StreamType.All
192
- direction: StreamDirection.All, // (optional) Direction, default is StreamDirection.All)
193
- cluster: Cluster.Mainnet, // (optional) Cluster, default is Cluster.Mainnet).
194
- });
225
+ const streams = StreamClient.get({
226
+ wallet: wallet, // Wallet signing the transaction.
227
+ type: StreamType.All, // (optional) Type, default is StreamType.All
228
+ direction: StreamDirection.All, // (optional) Direction, default is StreamDirection.All)
229
+ });
195
230
  } catch (exception) {
196
- // handle exception
231
+ // handle exception
197
232
  }
198
233
  ```
199
234
 
200
235
  ## Additional notes
201
236
 
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.
238
+
202
239
  Streamflow protocol program ID (devnet): `HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ`
203
- <br>
240
+
204
241
  Streamflow protocol program ID (mainnet): `strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m`
205
242
 
206
243
  **All BN amounts are denominated in their smallest units.**
@@ -213,4 +250,6 @@ Use `getBN` and `getNumberFromBN` utility functions for conversions between `BN`
213
250
 
214
251
  **Streamflow Community** (free and open source version, with a limited feature set) is available [here](https://github.com/streamflow-finance/js-sdk/tree/community).
215
252
 
253
+ `npx typedoc packages/stream/index.ts`
254
+
216
255
  WAGMI.
@@ -1,4 +1,4 @@
1
- import { Stream as StreamData, CreateStreamParams, WithdrawStreamParams, TopupStreamParams, CancelStreamParams, TransferStreamParams, GetStreamParams, GetStreamsParams, CreateStreamResponse, TransactionResponse } from "./types";
1
+ import { Stream as StreamData, GetStreamsParams, CreateStreamParams, CreateStreamResponse, WithdrawStreamParams, CancelStreamParams, TransactionResponse, TopupStreamParams, TransferStreamParams, GetStreamParams } from "./types";
2
2
  export default class Stream {
3
3
  /**
4
4
  * Creates a new stream/vesting contract.
@@ -22,7 +22,7 @@ export default class Stream {
22
22
  * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
23
23
  * @param {boolean} [data.automaticWithdrawal = false] - Whether or not a 3rd party can initiate withdraw in the name of recipient.
24
24
  * @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.
25
- * @param {string} [data.partner = ""] - Partner's wallet address (optional).
25
+ * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
26
26
  * @param {ClusterExtended} [data.cluster = Cluster.Mainnet] - Cluster: devnet, mainnet-beta, testnet or local (optional).
27
27
  */
28
28
  static create({ connection, sender, recipient, mint, start, depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, cluster, }: CreateStreamParams): Promise<CreateStreamResponse>;
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // Version 1 of the SDK that uses Anchor.
2
3
  var __assign = (this && this.__assign) || function () {
3
4
  __assign = Object.assign || function(t) {
4
5
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -75,6 +76,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
75
76
  return (mod && mod.__esModule) ? mod : { "default": mod };
76
77
  };
77
78
  Object.defineProperty(exports, "__esModule", { value: true });
79
+ var bn_js_1 = __importDefault(require("bn.js"));
80
+ var buffer_1 = require("buffer");
78
81
  var anchor_1 = require("@project-serum/anchor");
79
82
  var spl_token_1 = require("@solana/spl-token");
80
83
  var web3_js_1 = require("@solana/web3.js");
@@ -112,13 +115,13 @@ var Stream = /** @class */ (function () {
112
115
  * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
113
116
  * @param {boolean} [data.automaticWithdrawal = false] - Whether or not a 3rd party can initiate withdraw in the name of recipient.
114
117
  * @param {number} [data.withdrawalFrequency = 0] - Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
115
- * @param {string} [data.partner = ""] - Partner's wallet address (optional).
118
+ * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
116
119
  * @param {ClusterExtended} [data.cluster = Cluster.Mainnet] - Cluster: devnet, mainnet-beta, testnet or local (optional).
117
120
  */
118
121
  Stream.create = function (_a) {
119
122
  var connection = _a.connection, sender = _a.sender, recipient = _a.recipient, mint = _a.mint, start = _a.start, depositedAmount = _a.depositedAmount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _b = _a.automaticWithdrawal, automaticWithdrawal = _b === void 0 ? false : _b, _c = _a.withdrawalFrequency, withdrawalFrequency = _c === void 0 ? 0 : _c, _d = _a.partner, partner = _d === void 0 ? "" : _d, _e = _a.cluster, cluster = _e === void 0 ? types_1.Cluster.Mainnet : _e;
120
123
  return __awaiter(this, void 0, void 0, function () {
121
- var program, mintPublicKey, recipientPublicKey, metadata, _f, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, signers, nameUtf8EncodedBytes, tx;
124
+ var program, mintPublicKey, recipientPublicKey, metadata, _f, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, signers, nameUtf8EncodedArr, tx;
122
125
  return __generator(this, function (_g) {
123
126
  switch (_g.label) {
124
127
  case 0:
@@ -126,7 +129,7 @@ var Stream = /** @class */ (function () {
126
129
  mintPublicKey = new web3_js_1.PublicKey(mint);
127
130
  recipientPublicKey = new web3_js_1.PublicKey(recipient);
128
131
  metadata = web3_js_1.Keypair.generate();
129
- return [4 /*yield*/, anchor_1.web3.PublicKey.findProgramAddress([Buffer.from("strm"), metadata.publicKey.toBuffer()], program.programId)];
132
+ return [4 /*yield*/, anchor_1.web3.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], program.programId)];
130
133
  case 1:
131
134
  _f = __read.apply(void 0, [_g.sent(), 1]), escrowTokens = _f[0];
132
135
  return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
@@ -145,14 +148,14 @@ var Stream = /** @class */ (function () {
145
148
  case 5:
146
149
  partnerTokens = _g.sent();
147
150
  signers = [metadata];
148
- nameUtf8EncodedBytes = formatStringToBytesArray(encoder, name);
151
+ nameUtf8EncodedArr = encoder.encode(name);
149
152
  return [4 /*yield*/, program.rpc.create(
150
153
  // Order of the parameters must match the ones in the program
151
- new anchor_1.BN(start), depositedAmount, new anchor_1.BN(period), amountPerPeriod, new anchor_1.BN(cliff), cliffAmount, cancelableBySender, cancelableByRecipient, automaticWithdrawal, transferableBySender, transferableByRecipient, canTopup, nameUtf8EncodedBytes, new anchor_1.BN(automaticWithdrawal ? withdrawalFrequency : period), {
154
+ new bn_js_1.default(start), depositedAmount, new bn_js_1.default(period), amountPerPeriod, new bn_js_1.default(cliff), cliffAmount, cancelableBySender, cancelableByRecipient, automaticWithdrawal, transferableBySender, transferableByRecipient, canTopup, nameUtf8EncodedArr, new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period), {
152
155
  accounts: {
153
156
  sender: sender.publicKey,
154
157
  senderTokens: senderTokens,
155
- recipient: recipient,
158
+ recipient: new web3_js_1.PublicKey(recipient),
156
159
  metadata: metadata.publicKey,
157
160
  escrowTokens: escrowTokens,
158
161
  recipientTokens: recipientTokens,
@@ -160,7 +163,7 @@ var Stream = /** @class */ (function () {
160
163
  streamflowTreasuryTokens: streamflowTreasuryTokens,
161
164
  partner: partnerPublicKey,
162
165
  partnerTokens: partnerTokens,
163
- mint: mint,
166
+ mint: new web3_js_1.PublicKey(mint),
164
167
  feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
165
168
  rent: web3_js_1.SYSVAR_RENT_PUBKEY,
166
169
  timelockProgram: program.programId,
@@ -498,21 +501,3 @@ function ata(mint, account) {
498
501
  });
499
502
  });
500
503
  }
501
- function formatStringToBytesArray(encoder, text) {
502
- var textCopy = __spreadArray([], __read(text), false);
503
- var characters = Array.from(textCopy);
504
- var utf8EncodedBytes = [];
505
- characters.every(function (char) {
506
- if (utf8EncodedBytes.length > 64)
507
- return false;
508
- var encoded = encoder.encode(char);
509
- if (utf8EncodedBytes.length + encoded.length > 64)
510
- return false;
511
- encoded.forEach(function (elem) { return utf8EncodedBytes.push(new anchor_1.BN(elem)); });
512
- return true;
513
- });
514
- var numberOfBytes = utf8EncodedBytes.length;
515
- var fill = new Array(64 - numberOfBytes).fill(new anchor_1.BN(0));
516
- utf8EncodedBytes.push.apply(utf8EncodedBytes, __spreadArray([], __read(fill), false));
517
- return utf8EncodedBytes;
518
- }
@@ -0,0 +1,107 @@
1
+ import { web3 } from "@project-serum/anchor";
2
+ import { Commitment, ConnectionConfig } from "@solana/web3.js";
3
+ import { Stream as StreamData, CreateParams, CreateMultiParams, WithdrawParams, TopupParams, CancelParams, TransferParams, ClusterExtended, GetAllParams, CreateResponse, CreateMultiResponse, TxResponse } from "./types";
4
+ export default class StreamClient {
5
+ private connection;
6
+ private cluster;
7
+ private programId;
8
+ private commitment;
9
+ /**
10
+ * Create Stream instance
11
+ */
12
+ constructor(clusterUrl: string, cluster?: ClusterExtended, commitment?: Commitment | ConnectionConfig);
13
+ getConnection(): web3.Connection;
14
+ /**
15
+ * Creates a new stream/vesting contract.
16
+ * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
17
+ * @param {CreateParams} data
18
+ * @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
19
+ * @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
20
+ * @param {string} data.mint - SPL Token mint.
21
+ * @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
22
+ * @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
23
+ * @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
24
+ * @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
25
+ * @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
26
+ * @param {BN} data.amountPerPeriod - Amount unlocked per each period.
27
+ * @param {string} data.name - Stream name/subject.
28
+ * @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
29
+ * @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
30
+ * @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
31
+ * @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
32
+ * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
33
+ * @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
34
+ * @param {number} [data.withdrawalFrequency = 0] - Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
35
+ * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
36
+ */
37
+ create({ sender, recipient, mint, start, depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: CreateParams): Promise<CreateResponse>;
38
+ /**
39
+ * Creates a new stream/vesting contract.
40
+ * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
41
+ * @param {CreateMultiParams} data
42
+ * @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
43
+ * @param {MultiRecipient[]} data.recipientsData
44
+ * @param {string} data.mint - SPL Token mint.
45
+ * @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
46
+ * @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
47
+ * @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
48
+ * @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
49
+ * @param {BN} data.amountPerPeriod - Amount unlocked per each period.
50
+ * @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
51
+ * @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
52
+ * @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
53
+ * @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
54
+ * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
55
+ * @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
56
+ * @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.
57
+ * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
58
+ */
59
+ createMultiple({ sender, recipientsData, mint, start, period, cliff, cliffAmount, amountPerPeriod, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: CreateMultiParams): Promise<CreateMultiResponse>;
60
+ /**
61
+ * Attempts withdrawal from the specified stream.
62
+ * @param {WithdrawParams} data
63
+ * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (recipient) or transaction will fail.
64
+ * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be withdrawn from.
65
+ * @param {BN} data.amount - Requested amount (in the smallest units) to withdraw (while streaming). If stream is completed, the whole amount will be withdrawn.
66
+ */
67
+ withdraw({ invoker, id, amount, }: WithdrawParams): Promise<TxResponse>;
68
+ /**
69
+ * Attempts canceling the specified stream.
70
+ * @param {CancelParams} data
71
+ * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
72
+ * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be canceled.
73
+ */
74
+ cancel({ invoker, id }: CancelParams): Promise<TxResponse>;
75
+ /**
76
+ * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
77
+ * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
78
+ * @param {TransferParams} data
79
+ * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
80
+ * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be transferred.
81
+ * @param {string} data.recipientId - Address of a new recipient.
82
+ */
83
+ transfer({ invoker, id, recipientId, }: TransferParams): Promise<TxResponse>;
84
+ /**
85
+ * Tops up stream account deposited amount.
86
+ * @param {TopupParams} data
87
+ * @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match current stream sender or transaction will fail.
88
+ * @param {string} data.id - Identifier of a stream (escrow account with metadata) to be topped up.
89
+ * @param {BN} data.amount - Specified amount (in the smallest units) to topup (increases deposited amount).
90
+ */
91
+ topup({ invoker, id, amount, }: TopupParams): Promise<TxResponse>;
92
+ /**
93
+ * Fetch stream data by its id (address).
94
+ * @param {string} id - Identifier of a stream that is fetched.
95
+ */
96
+ getOne(id: string): Promise<StreamData>;
97
+ /**
98
+ * Fetch streams/contracts by providing direction.
99
+ * Streams are sorted by start time in ascending order.
100
+ * @param {GetAllParams} data
101
+ * @param {PublicKey} data.wallet - PublicKey of the wallet for which the streams/contracts are fetched.
102
+ * @param {StreamType} [data.type = StreamType.All] - It can be one of: stream, vesting, all.
103
+ * @param {StreamDirection} [data.direction = StreamDirection.All] - It can be one of: incoming, outgoing, all.
104
+ */
105
+ get({ wallet, type, direction, }: GetAllParams): Promise<[string, StreamData][]>;
106
+ private sign;
107
+ }