@streamflow/stream 2.0.2 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,32 +1,30 @@
1
- **Important: Security audit is underway.**
1
+ **Important: Security audit for the v2 is underway.**
2
2
 
3
3
  Docs: https://streamflow.finance/js-sdk/
4
+
4
5
  # Streamflow
5
- Streamflow is a token distribution platform powered by a streaming payments' protocol.
6
6
 
7
- Streamflow program ID (devnet) => `HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ`
8
- <br>
9
- Streamflow program ID (mainnet) => `strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m`
7
+ Streamflow is a token distribution platform powered by a streaming payments' protocol.
10
8
 
11
- There are several ways to use Streamflow protocol:
9
+ There are several ways to use **Streamflow**:
12
10
 
13
- - **(preferred) Application with UI** => [app.streamflow.finance](https://app.streamflow.finance)
14
- - **JS SDK** (this repo) => [NPM package](https://www.npmjs.com/package/@streamflow/stream/v/2.0.0)
15
- - **Rust SDK** for integration within Solana programs => [here](https://github.com/streamflow-finance/rust-sdk)
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)
13
+ - **[Rust SDK](https://github.com/streamflow-finance/rust-sdk)** to integrate within a Solana program => [Rust Crate](https://docs.rs/streamflow-sdk/)
16
14
 
17
- [**Streamflow Community** (free and open source, with limited features) is available here.](https://github.com/streamflow-finance/js-sdk/tree/community)
15
+ ## JS SDK
18
16
 
19
- ## JS SDK to interact with Streamflow protocol.
20
- This package allows you to `create`, `withdraw`, `cancel`, `topup` and `transfer` SPL token stream.
17
+ This SDK allows you to `create`, `withdraw`, `cancel`, `topup` and `transfer` SPL token stream.
21
18
 
22
19
  You can also `getOne` stream and `get` multiple streams.
23
20
 
24
- ### Install the Streamflow JS SDK
21
+ ---
25
22
 
26
- `npm i @streamflow/stream @solana/web3.js @project-serum/anchor`
23
+ ### Installation
27
24
 
25
+ `npm i @streamflow/stream @solana/web3.js @project-serum/anchor`
28
26
 
29
- >_Anchor is needed for the `Wallet` type. We plan on removing this dependency in upcoming releases._
27
+ > _Anchor is needed for the `Wallet` type. We plan on removing this dependency in upcoming releases._
30
28
 
31
29
  `bn.js` library is used for handling big numbers.
32
30
 
@@ -36,7 +34,9 @@ import { Wallet } from "@project-serum/anchor/src/provider";
36
34
  import BN from "bn.js";
37
35
  ```
38
36
 
39
- ## Import SDK
37
+ ### Usage
38
+
39
+ #### Imports
40
40
 
41
41
  Most common imports:
42
42
 
@@ -57,9 +57,10 @@ import Stream, {
57
57
  CreateStreamResponse,
58
58
  } from "@streamflow/stream";
59
59
  ```
60
+
60
61
  _Check the SDK for other types and utility functions._
61
62
 
62
- ### Create stream
63
+ #### Create stream
63
64
 
64
65
  ```javascript
65
66
  const createStreamParams = {
@@ -68,19 +69,20 @@ const createStreamParams = {
68
69
  recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Solana recipient address.
69
70
  mint: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // SPL Token mint.
70
71
  start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
71
- depositedAmount: new BN(1000000000000), // Deposited amount of tokens (in the smallest units).
72
+ depositedAmount: new BN(1000000000000), // Deposited amount of tokens (using smallest denomination).
72
73
  period: 1, // Time step (period) in seconds per which the unlocking occurs.
73
74
  cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds.
74
- cliffAmount: new BN(100000000000), // Amount unlocked at the "cliff" timestamp.
75
+ cliffAmount: new BN(100000000000), // Amount (smallest denomination) unlocked at the "cliff" timestamp.
75
76
  amountPerPeriod: new BN(5000000000), // Release rate: how many tokens are unlocked per each period.
76
- name: "Transfer to Jane Doe.", // The stream name/subject.
77
+ name: "Transfer to Jane Doe.", // The stream name or subject.
77
78
  canTopup: false, // setting to FALSE will effectively create a vesting contract.
78
79
  cancelableBySender: true, // Whether or not sender can cancel the stream.
79
80
  cancelableByRecipient: false, // Whether or not recipient can cancel the stream.
80
- transferableBySender: true, // Whether or not sender can transfer the stream.
81
- transferableByRecipient: false, // Whether or not recipient can transfer the stream.
82
- automaticWithdrawal: false, // Whether or not a 3rd party can initiate withdraw in the name of recipient (currently not used, set it to FALSE).
83
- partner: null, // (optional) Partner's wallet address (string | null).
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).
84
86
  cluster: Cluster.Mainnet, // (optional) Cluster (default is Cluster.Mainnet).
85
87
  };
86
88
 
@@ -91,7 +93,11 @@ try {
91
93
  }
92
94
  ```
93
95
 
94
- ## Withdraw from stream
96
+ \_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`.
97
+
98
+ Please note that transaction fees for the scheduled transfers are paid upfront by the stream creator (sender).\_
99
+
100
+ #### Withdraw from stream
95
101
 
96
102
  ```javascript
97
103
  const withdrawStreamParams = {
@@ -109,7 +115,7 @@ try {
109
115
  }
110
116
  ```
111
117
 
112
- ## Topup stream
118
+ #### Topup stream
113
119
 
114
120
  ```javascript
115
121
  const topupStreamParams = {
@@ -127,7 +133,7 @@ try {
127
133
  }
128
134
  ```
129
135
 
130
- ## Transfer stream to another recipient
136
+ #### Transfer stream to another recipient
131
137
 
132
138
  ```javascript
133
139
  const data = {
@@ -145,7 +151,7 @@ try {
145
151
  }
146
152
  ```
147
153
 
148
- ## Cancel stream
154
+ #### Cancel stream
149
155
 
150
156
  ```javascript
151
157
  const cancelStreamParams = {
@@ -162,7 +168,7 @@ try {
162
168
  }
163
169
  ```
164
170
 
165
- ## Get stream by ID
171
+ #### Get one stream by its ID
166
172
 
167
173
  ```javascript
168
174
  try {
@@ -175,7 +181,7 @@ try {
175
181
  }
176
182
  ```
177
183
 
178
- ## Get streams for a specific wallet address
184
+ #### Get multiple streams for a specific wallet address
179
185
 
180
186
  ```javascript
181
187
  try {
@@ -191,13 +197,20 @@ try {
191
197
  }
192
198
  ```
193
199
 
194
- ### Additional notes
200
+ ## Additional notes
195
201
 
196
- #### All BN amounts are denominated in their smallest units.
202
+ Streamflow protocol program ID (devnet): `HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ`
203
+ <br>
204
+ Streamflow protocol program ID (mainnet): `strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m`
205
+
206
+ **All BN amounts are denominated in their smallest units.**
207
+
208
+ E.g, if the amount is 1 SOL than this amount in lamports is `1000 \* 10^9 = 1_000_000_000.`
197
209
 
198
- E.g, if the amount is 1 SOL than this amount in lamports is 1000 \* 10^9 = 1_000_000_000.
199
210
  And `new BN(1_000_000_000)` is used.
200
211
 
201
212
  Use `getBN` and `getNumberFromBN` utility functions for conversions between `BN` and `Number` types.
202
213
 
203
- WAGMI.
214
+ **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
+
216
+ WAGMI.
@@ -10,3 +10,4 @@ export declare const PROGRAM_ID: {
10
10
  };
11
11
  export declare const STREAMFLOW_TREASURY_PUBLIC_KEY: PublicKey;
12
12
  export declare const WITHDRAWOR_PUBLIC_KEY: PublicKey;
13
+ export declare const FEE_ORACLE_PUBLIC_KEY: PublicKey;
package/dist/constants.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.PROGRAM_ID = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
4
+ exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.PROGRAM_ID = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
5
5
  var web3_js_1 = require("@solana/web3.js");
6
6
  var types_1 = require("./types");
7
7
  exports.TX_FINALITY_CONFIRMED = "confirmed";
@@ -15,3 +15,4 @@ exports.PROGRAM_ID = (_a = {},
15
15
  _a);
16
16
  exports.STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js_1.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
17
17
  exports.WITHDRAWOR_PUBLIC_KEY = new web3_js_1.PublicKey("wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u");
18
+ exports.FEE_ORACLE_PUBLIC_KEY = new web3_js_1.PublicKey("B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT");
package/dist/sdk.d.ts CHANGED
@@ -20,11 +20,12 @@ export default class Stream {
20
20
  * @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
21
21
  * @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
22
22
  * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
23
- * @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
24
- * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
23
+ * @param {boolean} [data.automaticWithdrawal = false] - Whether or not a 3rd party can initiate withdraw in the name of recipient.
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
26
  * @param {ClusterExtended} [data.cluster = Cluster.Mainnet] - Cluster: devnet, mainnet-beta, testnet or local (optional).
26
27
  */
27
- static create({ connection, sender, recipient, mint, start, depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, partner, cluster, }: CreateStreamParams): Promise<CreateStreamResponse>;
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>;
28
29
  /**
29
30
  * Attempts withdrawal from the specified stream.
30
31
  * @param {WithdrawStreamParams} data
package/dist/sdk.js CHANGED
@@ -110,16 +110,17 @@ var Stream = /** @class */ (function () {
110
110
  * @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
111
111
  * @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
112
112
  * @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
113
- * @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
114
- * @param {string | null} [data.partner = null] - Partner's wallet address (optional).
113
+ * @param {boolean} [data.automaticWithdrawal = false] - Whether or not a 3rd party can initiate withdraw in the name of recipient.
114
+ * @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).
115
116
  * @param {ClusterExtended} [data.cluster = Cluster.Mainnet] - Cluster: devnet, mainnet-beta, testnet or local (optional).
116
117
  */
117
118
  Stream.create = function (_a) {
118
- 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, automaticWithdrawal = _a.automaticWithdrawal, partner = _a.partner, _b = _a.cluster, cluster = _b === void 0 ? types_1.Cluster.Mainnet : _b;
119
+ 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;
119
120
  return __awaiter(this, void 0, void 0, function () {
120
- var program, mintPublicKey, recipientPublicKey, metadata, _c, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, signers, nameUtf8EncodedBytes, tx;
121
- return __generator(this, function (_d) {
122
- switch (_d.label) {
121
+ var program, mintPublicKey, recipientPublicKey, metadata, _f, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, signers, nameUtf8EncodedBytes, tx;
122
+ return __generator(this, function (_g) {
123
+ switch (_g.label) {
123
124
  case 0:
124
125
  program = initProgram(connection, sender, cluster);
125
126
  mintPublicKey = new web3_js_1.PublicKey(mint);
@@ -127,27 +128,27 @@ var Stream = /** @class */ (function () {
127
128
  metadata = web3_js_1.Keypair.generate();
128
129
  return [4 /*yield*/, anchor_1.web3.PublicKey.findProgramAddress([Buffer.from("strm"), metadata.publicKey.toBuffer()], program.programId)];
129
130
  case 1:
130
- _c = __read.apply(void 0, [_d.sent(), 1]), escrowTokens = _c[0];
131
+ _f = __read.apply(void 0, [_g.sent(), 1]), escrowTokens = _f[0];
131
132
  return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
132
133
  case 2:
133
- senderTokens = _d.sent();
134
+ senderTokens = _g.sent();
134
135
  return [4 /*yield*/, ata(mintPublicKey, recipientPublicKey)];
135
136
  case 3:
136
- recipientTokens = _d.sent();
137
+ recipientTokens = _g.sent();
137
138
  return [4 /*yield*/, ata(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
138
139
  case 4:
139
- streamflowTreasuryTokens = _d.sent();
140
+ streamflowTreasuryTokens = _g.sent();
140
141
  partnerPublicKey = partner
141
142
  ? new web3_js_1.PublicKey(partner)
142
- : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
143
+ : sender.publicKey;
143
144
  return [4 /*yield*/, ata(mintPublicKey, partnerPublicKey)];
144
145
  case 5:
145
- partnerTokens = _d.sent();
146
+ partnerTokens = _g.sent();
146
147
  signers = [metadata];
147
148
  nameUtf8EncodedBytes = formatStringToBytesArray(encoder, name);
148
149
  return [4 /*yield*/, program.rpc.create(
149
150
  // Order of the parameters must match the ones in the program
150
- 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(period), {
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), {
151
152
  accounts: {
152
153
  sender: sender.publicKey,
153
154
  senderTokens: senderTokens,
@@ -160,7 +161,7 @@ var Stream = /** @class */ (function () {
160
161
  partner: partnerPublicKey,
161
162
  partnerTokens: partnerTokens,
162
163
  mint: mint,
163
- feeOracle: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
164
+ feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
164
165
  rent: web3_js_1.SYSVAR_RENT_PUBKEY,
165
166
  timelockProgram: program.programId,
166
167
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
@@ -171,7 +172,7 @@ var Stream = /** @class */ (function () {
171
172
  signers: signers,
172
173
  })];
173
174
  case 6:
174
- tx = _d.sent();
175
+ tx = _g.sent();
175
176
  return [2 /*return*/, { tx: tx, id: metadata.publicKey.toBase58() }];
176
177
  }
177
178
  });
@@ -211,7 +212,7 @@ var Stream = /** @class */ (function () {
211
212
  return [4 /*yield*/, program.rpc.withdraw(amount, {
212
213
  accounts: {
213
214
  authority: invoker.publicKey,
214
- recipient: invoker.publicKey,
215
+ recipient: data.recipient,
215
216
  recipientTokens: data.recipientTokens,
216
217
  metadata: streamPublicKey,
217
218
  escrowTokens: data.escrowTokens,
package/dist/types.d.ts CHANGED
@@ -38,12 +38,13 @@ export interface CreateStreamData {
38
38
  cancelableByRecipient: boolean;
39
39
  transferableBySender: boolean;
40
40
  transferableByRecipient: boolean;
41
- automaticWithdrawal: boolean;
41
+ automaticWithdrawal?: boolean;
42
+ withdrawalFrequency?: number;
42
43
  }
43
44
  export interface CreateStreamParams extends CreateStreamData {
44
45
  connection: Connection;
45
46
  sender: Wallet;
46
- partner?: string | null;
47
+ partner?: string;
47
48
  cluster?: ClusterExtended;
48
49
  }
49
50
  export interface WithdrawStreamData {
@@ -129,7 +130,7 @@ export interface Stream {
129
130
  transferableByRecipient: boolean;
130
131
  canTopup: boolean;
131
132
  name: string;
132
- withdrawFrequency: number;
133
+ withdrawalFrequency: number;
133
134
  }
134
135
  export interface DecodedStream {
135
136
  magic: BN;
@@ -168,7 +169,7 @@ export interface DecodedStream {
168
169
  transferableByRecipient: boolean;
169
170
  canTopup: boolean;
170
171
  name: string;
171
- withdrawFrequency: BN;
172
+ withdrawalFrequency: BN;
172
173
  }
173
174
  export interface TransactionResponse {
174
175
  tx: TransactionSignature;
package/dist/utils.js CHANGED
@@ -87,7 +87,7 @@ var decodeStream = function (buf) {
87
87
  transferableByRecipient: Boolean(raw.transferable_by_recipient),
88
88
  canTopup: Boolean(raw.can_topup),
89
89
  name: decoder.decode(raw.stream_name),
90
- withdrawFrequency: new anchor_1.BN(raw.withdraw_frequency, LE),
90
+ withdrawalFrequency: new anchor_1.BN(raw.withdraw_frequency, LE),
91
91
  };
92
92
  };
93
93
  exports.decodeStream = decodeStream;
@@ -130,7 +130,7 @@ var formatDecodedStream = function (stream) {
130
130
  transferableByRecipient: stream.transferableByRecipient,
131
131
  canTopup: stream.canTopup,
132
132
  name: stream.name,
133
- withdrawFrequency: stream.withdrawFrequency.toNumber(),
133
+ withdrawalFrequency: stream.withdrawalFrequency.toNumber(),
134
134
  });
135
135
  };
136
136
  exports.formatDecodedStream = formatDecodedStream;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "2.0.2",
3
+ "version": "2.2.1",
4
4
  "description": "JavaScript SDK to interact with Streamflow protocol.",
5
5
  "main": "dist/index.js",
6
6
  "homepage": "https://github.com/streamflow-finance/js-sdk/",