@streamflow/stream 5.0.0 → 5.1.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 +236 -126
- package/dist/aptos/types.d.ts +1 -45
- package/dist/aptos/types.js +12 -1
- package/dist/common/BaseStreamClient.d.ts +1 -2
- package/dist/common/GenericStreamClient.d.ts +16 -11
- package/dist/common/GenericStreamClient.js +14 -56
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +4 -0
- package/dist/common/contractUtils.d.ts +13 -1
- package/dist/common/contractUtils.js +2 -1
- package/dist/common/types.d.ts +45 -0
- package/dist/evm/StreamClient.d.ts +1 -2
- package/dist/evm/StreamClient.js +1 -1
- package/dist/evm/types.d.ts +1 -45
- package/dist/evm/types.js +12 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/solana/StreamClient.d.ts +4 -4
- package/dist/solana/constants.d.ts +0 -1
- package/dist/solana/constants.js +1 -2
- package/dist/solana/instructions.js +1 -1
- package/dist/solana/types.d.ts +1 -46
- package/dist/solana/types.js +12 -1
- package/dist/solana/utils.d.ts +2 -1
- package/dist/sui/StreamClient.d.ts +78 -0
- package/dist/sui/StreamClient.js +542 -0
- package/dist/sui/constants.d.ts +4 -0
- package/dist/sui/constants.js +23 -0
- package/dist/sui/index.d.ts +2 -0
- package/dist/sui/index.js +23 -0
- package/dist/sui/types.d.ts +137 -0
- package/dist/sui/types.js +163 -0
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
Docs: https://streamflow.finance/js-sdk/
|
|
2
|
-
|
|
3
1
|
# Streamflow
|
|
4
2
|
|
|
5
|
-
Streamflow is a token
|
|
3
|
+
Streamflow is a token vesting and streaming payments platform.
|
|
6
4
|
|
|
7
5
|
There are several ways to use **Streamflow**:
|
|
8
6
|
|
|
@@ -12,12 +10,12 @@ There are several ways to use **Streamflow**:
|
|
|
12
10
|
|
|
13
11
|
**Security audit passed ✅**
|
|
14
12
|
|
|
15
|
-
Protocol
|
|
13
|
+
Protocol audits available [here](https://www.notion.so/streamflow/Streamflow-Security-Audits-3250070c0b3a4a0690385d96316d645c).
|
|
16
14
|
Partner oracle audit available here [here](https://github.com/streamflow-finance/rust-sdk/blob/main/partner_oracle_audit.pdf).
|
|
17
15
|
|
|
18
16
|
## JS SDK to interact with Streamflow protocol.
|
|
19
17
|
|
|
20
|
-
This package allows you to `create`, `createMultiple`, `withdraw`, `cancel`, `topup
|
|
18
|
+
This package allows you to `create`, `createMultiple`, `withdraw`, `cancel`, `topup`, `transfer`, `update` a token stream.
|
|
21
19
|
|
|
22
20
|
You can also `getOne` stream and `get` multiple streams.
|
|
23
21
|
|
|
@@ -37,54 +35,103 @@ or
|
|
|
37
35
|
Most common imports:
|
|
38
36
|
|
|
39
37
|
```javascript
|
|
40
|
-
import {
|
|
41
|
-
|
|
42
|
-
StreamflowSolana,
|
|
43
|
-
StreamflowAptos,
|
|
44
|
-
Types,
|
|
45
|
-
getBN,
|
|
46
|
-
getNumberFromBN,
|
|
47
|
-
} from "@streamflow/stream";
|
|
38
|
+
import { BN } from "bn.js";
|
|
39
|
+
import { Types, GenericStreamClient, getBN, getNumberFromBN } from "@streamflow/stream";
|
|
48
40
|
```
|
|
49
41
|
|
|
50
42
|
_Check the SDK for other types and utility functions._
|
|
51
43
|
|
|
52
44
|
## Create StreamClient instance
|
|
53
45
|
|
|
54
|
-
Before creating and manipulating streams chain specific or generic StreamClient instance must be created.
|
|
55
|
-
All streams functions are methods on this instance.
|
|
46
|
+
Before creating and manipulating streams chain specific or generic StreamClient instance must be created. All streams functions are methods on this instance.
|
|
56
47
|
|
|
57
48
|
### Solana
|
|
49
|
+
|
|
58
50
|
```javascript
|
|
59
|
-
import {
|
|
51
|
+
import {
|
|
52
|
+
StreamflowSolana,
|
|
53
|
+
Types,
|
|
54
|
+
} from "@streamflow/stream";
|
|
60
55
|
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
Types.ICluster.Mainnet, // (optional) (default: Mainnet) Solana cluster
|
|
64
|
-
"confirmed", // (optional) (default: confirmed) Transaction commitment
|
|
56
|
+
const solanaClient = new StreamflowSolana.SolanaStreamClient(
|
|
57
|
+
"https://api.mainnet-beta.solana.com"
|
|
65
58
|
);
|
|
66
59
|
```
|
|
60
|
+
|
|
67
61
|
### Aptos
|
|
62
|
+
|
|
68
63
|
```javascript
|
|
69
|
-
import {
|
|
64
|
+
import {
|
|
65
|
+
StreamflowAptos,
|
|
66
|
+
Types,
|
|
67
|
+
} from "@streamflow/stream";
|
|
70
68
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
Types.ICluster.Mainnet, // (optional) (default: Mainnet) Aptos cluster
|
|
74
|
-
"10000", // (optional) (default: "10000") maxGas for transactions
|
|
69
|
+
const aptosClient = new StreamflowAptos.AptosStreamClient(
|
|
70
|
+
"https://fullnode.mainnet.aptoslabs.com/v1"
|
|
75
71
|
);
|
|
76
72
|
```
|
|
73
|
+
|
|
74
|
+
### Ethereum
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
import {
|
|
78
|
+
StreamflowEVM,
|
|
79
|
+
Types,
|
|
80
|
+
} from "@streamflow/stream";
|
|
81
|
+
|
|
82
|
+
const ethereumClient = new StreamflowEVM.EvmStreamClient(
|
|
83
|
+
"YOUR_ETHEREUM_NODE_URL",
|
|
84
|
+
Types.IChain.Ethereum,
|
|
85
|
+
signer // will be sender in a stream and authority for all stream related transactions
|
|
86
|
+
);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
### Polygon
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
import {
|
|
94
|
+
StreamflowEVM,
|
|
95
|
+
Types,
|
|
96
|
+
} from "@streamflow/stream";
|
|
97
|
+
|
|
98
|
+
const polygonClient = new StreamflowEVM.EvmStreamClient(
|
|
99
|
+
"YOUR_POLYGON_NODE_URL",
|
|
100
|
+
Types.IChain.Polygon,
|
|
101
|
+
signer // will be sender in a stream and authority for all stream related transactions
|
|
102
|
+
);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### BNB
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
import {
|
|
109
|
+
StreamflowEVM,
|
|
110
|
+
Types,
|
|
111
|
+
} from "@streamflow/stream";
|
|
112
|
+
|
|
113
|
+
const bnbClient = new StreamflowEVM.EvmStreamClient(
|
|
114
|
+
"https://bsc-dataseed1.binance.org/",
|
|
115
|
+
Types.IChain.BNB,
|
|
116
|
+
signer // will be sender in a stream and authority for all stream related transactions
|
|
117
|
+
);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
|
|
77
121
|
### Generic Stream Client
|
|
78
|
-
|
|
122
|
+
|
|
123
|
+
GenericStreamClient provides isomorphic interface to work with streams agnostic of chain.
|
|
124
|
+
|
|
79
125
|
```javascript
|
|
80
126
|
import { GenericStreamClient, Types } from "@streamflow/stream";
|
|
81
127
|
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
128
|
+
const client =
|
|
129
|
+
new GenericStreamClient<Types.IChain.Solana>({
|
|
130
|
+
chain: Types.IChain.Solana, // Blockchain
|
|
131
|
+
clusterUrl: "https://api.mainnet-beta.solana.com", // RPC cluster URL
|
|
85
132
|
cluster: Types.ICluster.Mainnet, // (optional) (default: Mainnet)
|
|
86
133
|
// ...rest chain specific params e.g. commitment for Solana
|
|
87
|
-
});
|
|
134
|
+
});
|
|
88
135
|
```
|
|
89
136
|
|
|
90
137
|
All the examples below will contain generic method options descriptions and chain specific params.
|
|
@@ -94,30 +141,28 @@ All the examples below will contain generic method options descriptions and chai
|
|
|
94
141
|
## Create stream
|
|
95
142
|
|
|
96
143
|
```javascript
|
|
97
|
-
const createStreamParams = {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
canUpdateRate: fakse, // [optional] [WIP] Wether stream rate can be updated
|
|
144
|
+
const createStreamParams: Types.ICreateStreamData = {
|
|
145
|
+
recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Recipient address.
|
|
146
|
+
tokenId: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // Token mint address.
|
|
147
|
+
start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
|
|
148
|
+
amount: getBN(100, 9), // depositing 100 tokens with 9 decimals mint.
|
|
149
|
+
period: 1, // Time step (period) in seconds per which the unlocking occurs.
|
|
150
|
+
cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds.
|
|
151
|
+
cliffAmount: new BN(10), // Amount unlocked at the "cliff" timestamp.
|
|
152
|
+
amountPerPeriod: getBN(5, 9), // Release rate: how many tokens are unlocked per each period.
|
|
153
|
+
name: "Transfer to Jane Doe.", // The stream name or subject.
|
|
154
|
+
canTopup: false, // setting to FALSE will effectively create a vesting contract.
|
|
155
|
+
cancelableBySender: true, // Whether or not sender can cancel the stream.
|
|
156
|
+
cancelableByRecipient: false, // Whether or not recipient can cancel the stream.
|
|
157
|
+
transferableBySender: true, // Whether or not sender can transfer the stream.
|
|
158
|
+
transferableByRecipient: false, // Whether or not recipient can transfer the stream.
|
|
159
|
+
automaticWithdrawal: true, // Whether or not a 3rd party (e.g. cron job, "cranker") can initiate a token withdraw/transfer.
|
|
160
|
+
withdrawalFrequency: 10, // Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
|
|
161
|
+
partner: null, // (optional) Partner's wallet address (string | null).
|
|
116
162
|
};
|
|
117
163
|
|
|
118
164
|
const solanaParams = {
|
|
119
165
|
sender: wallet, // SignerWalletAdapter or Keypair of Sender account
|
|
120
|
-
partner: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // [optional] Partner Solana address
|
|
121
166
|
isNative: // [optional] [WILL CREATE A wSOL STREAM] Wether Stream or Vesting should be paid with Solana native token or not
|
|
122
167
|
};
|
|
123
168
|
|
|
@@ -125,10 +170,12 @@ const aptosParams = {
|
|
|
125
170
|
senderWallet: wallet, // AptosWalletAdapter Wallet of sender
|
|
126
171
|
};
|
|
127
172
|
|
|
173
|
+
const ethereumParams = undefined;
|
|
174
|
+
|
|
128
175
|
try {
|
|
129
|
-
|
|
176
|
+
const { ixs, tx, metadata } = await client.create(createStreamParams, solanaParams); // second argument differ depending on a chain
|
|
130
177
|
} catch (exception) {
|
|
131
|
-
|
|
178
|
+
// handle exception
|
|
132
179
|
}
|
|
133
180
|
```
|
|
134
181
|
|
|
@@ -136,35 +183,32 @@ try {
|
|
|
136
183
|
|
|
137
184
|
```javascript
|
|
138
185
|
const recipients = [
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
// ... Other Recipient options
|
|
186
|
+
{
|
|
187
|
+
recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Solana recipient address.
|
|
188
|
+
amount: getBN(100, 9), // depositing 100 tokens with 9 decimals mint.
|
|
189
|
+
name: "January Payroll", // The stream name/subject.
|
|
190
|
+
cliffAmount: getBN(10, 9), // amount released on cliff for this recipient
|
|
191
|
+
amountPerPeriod: getBN(1, 9), //amount released every specified period epoch
|
|
192
|
+
},
|
|
147
193
|
];
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
canUpdateRate: false, // [optional] [WIP] Wether stream rate can be updated
|
|
194
|
+
const createStreamParams: Types.ICreateMultipleStreamData = {
|
|
195
|
+
recipients: recipients, // Solana recipient address.
|
|
196
|
+
tokenId: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // SPL Token mint.
|
|
197
|
+
start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
|
|
198
|
+
period: 1, // Time step (period) in seconds per which the unlocking occurs.
|
|
199
|
+
cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds.
|
|
200
|
+
canTopup: false, // setting to FALSE will effectively create a vesting contract.
|
|
201
|
+
cancelableBySender: true, // Whether or not sender can cancel the stream.
|
|
202
|
+
cancelableByRecipient: false, // Whether or not recipient can cancel the stream.
|
|
203
|
+
transferableBySender: true, // Whether or not sender can transfer the stream.
|
|
204
|
+
transferableByRecipient: false, // Whether or not recipient can transfer the stream.
|
|
205
|
+
automaticWithdrawal: true, // Whether or not a 3rd party (e.g. cron job, "cranker") can initiate a token withdraw/transfer.
|
|
206
|
+
withdrawalFrequency: 10, // Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
|
|
207
|
+
partner: null, // (optional) Partner's wallet address (string | null).
|
|
163
208
|
};
|
|
164
209
|
|
|
165
210
|
const solanaParams = {
|
|
166
211
|
sender: wallet, // SignerWalletAdapter or Keypair of Sender account
|
|
167
|
-
partner: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // [optional] Partner Solana address
|
|
168
212
|
isNative: // [optional] [WILL CREATE A wSOL STREAM] Wether Stream or Vesting should be paid with Solana native token or not
|
|
169
213
|
};
|
|
170
214
|
|
|
@@ -172,149 +216,219 @@ const aptosParams = {
|
|
|
172
216
|
senderWallet: wallet, // AptosWalletAdapter Wallet of sender
|
|
173
217
|
};
|
|
174
218
|
|
|
219
|
+
const ethereumParams = undefined;
|
|
220
|
+
|
|
175
221
|
try {
|
|
176
|
-
|
|
222
|
+
const { txs } = await client.createMultiple(createMultiStreamsParams, solanaParams);
|
|
177
223
|
} catch (exception) {
|
|
178
|
-
|
|
224
|
+
// handle exception
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Please note that transaction fees for the scheduled transfers are paid upfront by the stream creator (sender).
|
|
229
|
+
|
|
230
|
+
## Identifying created contracts (streams or vesting)
|
|
231
|
+
|
|
232
|
+
All Stream Clients return `Types.ICreateResult` object (`createdMultiple` returns an Array) that has the following structure
|
|
233
|
+
|
|
234
|
+
```javascript
|
|
235
|
+
interface ICreateResult {
|
|
236
|
+
ixs: (TransactionInstruction | Types.TransactionPayload)[];
|
|
237
|
+
txId: string;
|
|
238
|
+
metadataId: MetadataId;
|
|
179
239
|
}
|
|
180
240
|
```
|
|
181
241
|
|
|
242
|
+
`metadataId` is the id of the created stream.
|
|
243
|
+
|
|
182
244
|
## Withdraw from stream
|
|
183
245
|
|
|
184
246
|
```javascript
|
|
185
|
-
const withdrawStreamParams = {
|
|
186
|
-
|
|
187
|
-
|
|
247
|
+
const withdrawStreamParams: Types.IWithdrawData = {
|
|
248
|
+
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be withdrawn from.
|
|
249
|
+
amount: getBN(100, 9), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
|
|
188
250
|
};
|
|
189
251
|
|
|
190
252
|
const solanaParams = {
|
|
191
|
-
invoker: wallet, //
|
|
253
|
+
invoker: wallet, // SignerWalletAdapter or Keypair signing the transaction
|
|
192
254
|
};
|
|
193
255
|
|
|
194
256
|
const aptosParams = {
|
|
195
|
-
senderWallet: wallet, // AptosWalletAdapter Wallet of
|
|
257
|
+
senderWallet: wallet, // AptosWalletAdapter Wallet of wallet signing the transaction
|
|
196
258
|
tokenId: "0x1::aptos_coin::AptosCoin", // Aptos Coin type
|
|
197
259
|
};
|
|
198
260
|
|
|
261
|
+
const ethereumParams = undefined;
|
|
199
262
|
|
|
200
263
|
try {
|
|
201
|
-
|
|
264
|
+
const { ixs, tx } = await client.withdraw(withdrawStreamParams, solanaParams);
|
|
202
265
|
} catch (exception) {
|
|
203
|
-
|
|
266
|
+
// handle exception
|
|
204
267
|
}
|
|
205
268
|
```
|
|
206
269
|
|
|
207
270
|
## Topup stream
|
|
208
271
|
|
|
209
272
|
```javascript
|
|
210
|
-
const topupStreamParams = {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
amount: getBN(100000000000, 9), // Specified amount to topup (increases deposited amount).
|
|
273
|
+
const topupStreamParams: Types.ITopUpData = {
|
|
274
|
+
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be topped up.
|
|
275
|
+
amount: getBN(100, 9), // Specified amount to topup (increases deposited amount).
|
|
214
276
|
};
|
|
215
277
|
|
|
216
278
|
const solanaParams = {
|
|
217
|
-
invoker: wallet, //
|
|
279
|
+
invoker: wallet, // SignerWalletAdapter or Keypair signing the transaction
|
|
218
280
|
isNative: // [ONLY FOR wSOL STREAMS] [optional] Wether topup is with Native Solanas
|
|
219
281
|
};
|
|
220
282
|
|
|
221
283
|
const aptosParams = {
|
|
222
|
-
senderWallet: wallet, // AptosWalletAdapter Wallet of
|
|
284
|
+
senderWallet: wallet, // AptosWalletAdapter Wallet of wallet signing the transaction
|
|
223
285
|
tokenId: "0x1::aptos_coin::AptosCoin", // Aptos Coin type
|
|
224
286
|
};
|
|
225
287
|
|
|
288
|
+
const ethereumParams = undefined;
|
|
289
|
+
|
|
226
290
|
try {
|
|
227
|
-
|
|
291
|
+
const { ixs, tx } = await client.topup(topupStreamParams, solanaParams);
|
|
228
292
|
} catch (exception) {
|
|
229
|
-
|
|
293
|
+
// handle exception
|
|
230
294
|
}
|
|
231
295
|
```
|
|
232
296
|
|
|
233
297
|
## Transfer stream to another recipient
|
|
234
298
|
|
|
235
299
|
```javascript
|
|
236
|
-
const data = {
|
|
237
|
-
|
|
238
|
-
|
|
300
|
+
const data: Types.ITransferData = {
|
|
301
|
+
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
|
|
302
|
+
newRecipient: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99", // Identifier of a stream to be transferred.
|
|
239
303
|
};
|
|
240
304
|
|
|
241
305
|
const solanaParams = {
|
|
242
|
-
invoker: wallet, //
|
|
306
|
+
invoker: wallet, // SignerWalletAdapter or Keypair signing the transaction
|
|
243
307
|
};
|
|
244
308
|
|
|
245
309
|
const aptosParams = {
|
|
246
|
-
senderWallet: wallet, // AptosWalletAdapter Wallet of
|
|
310
|
+
senderWallet: wallet, // AptosWalletAdapter Wallet of wallet signing the transaction
|
|
247
311
|
tokenId: "0x1::aptos_coin::AptosCoin", // Aptos Coin type
|
|
248
312
|
};
|
|
249
313
|
|
|
314
|
+
const ethereumParams = undefined;
|
|
250
315
|
|
|
251
316
|
try {
|
|
252
|
-
|
|
317
|
+
const { tx } = await client.transfer(data, solanaParams);
|
|
253
318
|
} catch (exception) {
|
|
254
|
-
|
|
319
|
+
// handle exception
|
|
255
320
|
}
|
|
256
321
|
```
|
|
257
322
|
|
|
258
323
|
## Cancel stream
|
|
259
324
|
|
|
260
325
|
```javascript
|
|
261
|
-
const cancelStreamParams = {
|
|
262
|
-
|
|
326
|
+
const cancelStreamParams: Types.ICancelData = {
|
|
327
|
+
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be canceled.
|
|
263
328
|
};
|
|
264
329
|
|
|
265
330
|
const solanaParams = {
|
|
266
|
-
invoker: wallet, //
|
|
331
|
+
invoker: wallet, // SignerWalletAdapter or Keypair signing the transaction
|
|
267
332
|
};
|
|
268
333
|
|
|
269
334
|
const aptosParams = {
|
|
270
|
-
senderWallet: wallet, // AptosWalletAdapter Wallet of
|
|
335
|
+
senderWallet: wallet, // AptosWalletAdapter Wallet of wallet signing the transaction
|
|
271
336
|
tokenId: "0x1::aptos_coin::AptosCoin", // Aptos Coin type
|
|
272
337
|
};
|
|
273
338
|
|
|
339
|
+
const ethereumParams = undefined;
|
|
340
|
+
|
|
274
341
|
try {
|
|
275
|
-
|
|
342
|
+
const { ixs, tx } = await StreamClient.cancel(cancelStreamParams, solanaParams);
|
|
276
343
|
} catch (exception) {
|
|
277
|
-
|
|
344
|
+
// handle exception
|
|
278
345
|
}
|
|
279
346
|
```
|
|
280
347
|
|
|
281
348
|
## Get one stream by its ID
|
|
282
349
|
|
|
283
350
|
```javascript
|
|
351
|
+
const data: Types.IGetOneData = {
|
|
352
|
+
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream
|
|
353
|
+
};
|
|
354
|
+
|
|
284
355
|
try {
|
|
285
|
-
|
|
286
|
-
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA" // Identifier of a stream that is fetched.
|
|
287
|
-
});
|
|
356
|
+
const stream = await client.getOne(data);
|
|
288
357
|
} catch (exception) {
|
|
289
|
-
|
|
358
|
+
// handle exception
|
|
290
359
|
}
|
|
291
360
|
```
|
|
292
361
|
|
|
362
|
+
## Fetching unlocked amount
|
|
363
|
+
|
|
364
|
+
```javascript
|
|
365
|
+
const stream = await client.getOne({
|
|
366
|
+
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
const unlocked = stream.unlocked(tsInSeconds); // bn amount unlocked at the tsInSeconds
|
|
370
|
+
console.log(getNumberFromBN(unlocked, 9));
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
- Note: unlocked amount is determined based on configuration set on creation, no dynamic data is involved.
|
|
374
|
+
|
|
375
|
+
## Reading withdrawn amount and remaining funds
|
|
376
|
+
|
|
377
|
+
```javascript
|
|
378
|
+
const stream = await client.getOne({
|
|
379
|
+
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
|
|
380
|
+
});
|
|
381
|
+
const withdrawn = stream.withdrawnAmount; // bn amount withdrawn already
|
|
382
|
+
console.log(getNumberFromBN(wihtdrawn, 9));
|
|
383
|
+
const remaining = stream.remaining(9); // amount of remaining funds
|
|
384
|
+
console.log(remaining);
|
|
385
|
+
```
|
|
386
|
+
|
|
293
387
|
## Get multiple streams for a specific wallet address
|
|
294
|
-
**NOTE: ONLY SUPPORTED FOR SOLANA CLIENT**
|
|
295
388
|
|
|
296
389
|
```javascript
|
|
390
|
+
const data: Types.IGetAllData = {
|
|
391
|
+
address: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99",
|
|
392
|
+
type: Types.StreamType.All,
|
|
393
|
+
direction: Types.StreamDirection.All,
|
|
394
|
+
};
|
|
395
|
+
|
|
297
396
|
try {
|
|
298
|
-
|
|
299
|
-
wallet: wallet, // Wallet signing the transaction.
|
|
300
|
-
type: StreamType.All, // (optional) Type, default is StreamType.All
|
|
301
|
-
direction: StreamDirection.All, // (optional) Direction, default is StreamDirection.All)
|
|
302
|
-
});
|
|
397
|
+
const streams = client.get(data);
|
|
303
398
|
} catch (exception) {
|
|
304
|
-
|
|
399
|
+
// handle exception
|
|
305
400
|
}
|
|
306
401
|
```
|
|
307
402
|
|
|
308
|
-
##
|
|
403
|
+
## Handling errors
|
|
404
|
+
|
|
405
|
+
Protocol raises custom errors on:
|
|
406
|
+
|
|
407
|
+
- validation errors
|
|
408
|
+
- state missmatch errors (such as canceling a stream that is complete/already canceled)
|
|
309
409
|
|
|
310
|
-
|
|
410
|
+
Errors are returned per blockchain specification format.
|
|
311
411
|
|
|
312
|
-
|
|
412
|
+
A public map of protocol errors is available [here](https://streamflow.notion.site/Streamflow-protocol-docs-0accad86d5c44e5db84fd4fb49b8ff54).
|
|
313
413
|
|
|
314
|
-
|
|
414
|
+
## Additional notes
|
|
415
|
+
|
|
416
|
+
Streamflow protocol program IDs
|
|
417
|
+
|
|
418
|
+
| Solana | |
|
|
419
|
+
| ------- | -------------------------------------------- |
|
|
420
|
+
| Devet | HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ |
|
|
421
|
+
| Mainnet | strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m |
|
|
315
422
|
|
|
316
|
-
|
|
423
|
+
| EVM | Ethereum(Goerli on Tesnet),Polygon,BNB |
|
|
424
|
+
| ------- | ------------------------------------------ |
|
|
425
|
+
| Testnet | 0x5Db7a43D20De64E3a3BC765334a477026FD13E7d |
|
|
426
|
+
| Mainnet | 0x94d4646Bd307Bf91CB1893BC64d976BF9E60D9B2 |
|
|
317
427
|
|
|
428
|
+
| Aptos | |
|
|
429
|
+
| ------- | ------------------------------------------------------------------ |
|
|
430
|
+
| Testnet | 0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688 |
|
|
431
|
+
| Mainnet | 0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0 |
|
|
318
432
|
|
|
319
433
|
**All BN amounts are denominated in their smallest units.**
|
|
320
434
|
|
|
@@ -324,8 +438,4 @@ And `new BN(1_000_000_000)` is used.
|
|
|
324
438
|
|
|
325
439
|
Use `getBN` and `getNumberFromBN` utility functions for conversions between `BN` and `Number` types.
|
|
326
440
|
|
|
327
|
-
**Streamflow Community** (free and open source version, with a limited feature set) is available [here](https://github.com/streamflow-finance/js-sdk/tree/community).
|
|
328
|
-
|
|
329
|
-
`npx typedoc packages/stream/index.ts`
|
|
330
|
-
|
|
331
441
|
WAGMI.
|
package/dist/aptos/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { WalletContextState } from "@manahippo/aptos-wallet-adapter";
|
|
2
2
|
import BN from "bn.js";
|
|
3
|
+
import { Stream } from "../common/types";
|
|
3
4
|
export interface ICreateStreamAptosExt {
|
|
4
5
|
senderWallet: WalletContextState;
|
|
5
6
|
}
|
|
@@ -45,51 +46,6 @@ export interface StreamResource {
|
|
|
45
46
|
start: string;
|
|
46
47
|
withdrawn: string;
|
|
47
48
|
}
|
|
48
|
-
export interface Stream {
|
|
49
|
-
magic: number;
|
|
50
|
-
version: number;
|
|
51
|
-
createdAt: number;
|
|
52
|
-
withdrawnAmount: BN;
|
|
53
|
-
canceledAt: number;
|
|
54
|
-
end: number;
|
|
55
|
-
lastWithdrawnAt: number;
|
|
56
|
-
sender: string;
|
|
57
|
-
senderTokens: string;
|
|
58
|
-
recipient: string;
|
|
59
|
-
recipientTokens: string;
|
|
60
|
-
mint: string;
|
|
61
|
-
escrowTokens: string;
|
|
62
|
-
streamflowTreasury: string;
|
|
63
|
-
streamflowTreasuryTokens: string;
|
|
64
|
-
streamflowFeeTotal: BN;
|
|
65
|
-
streamflowFeeWithdrawn: BN;
|
|
66
|
-
streamflowFeePercent: number;
|
|
67
|
-
partnerFeeTotal: BN;
|
|
68
|
-
partnerFeeWithdrawn: BN;
|
|
69
|
-
partnerFeePercent: number;
|
|
70
|
-
partner: string;
|
|
71
|
-
partnerTokens: string;
|
|
72
|
-
start: number;
|
|
73
|
-
depositedAmount: BN;
|
|
74
|
-
period: number;
|
|
75
|
-
amountPerPeriod: BN;
|
|
76
|
-
cliff: number;
|
|
77
|
-
cliffAmount: BN;
|
|
78
|
-
cancelableBySender: boolean;
|
|
79
|
-
cancelableByRecipient: boolean;
|
|
80
|
-
automaticWithdrawal: boolean;
|
|
81
|
-
transferableBySender: boolean;
|
|
82
|
-
transferableByRecipient: boolean;
|
|
83
|
-
canTopup: boolean;
|
|
84
|
-
name: string;
|
|
85
|
-
withdrawalFrequency: number;
|
|
86
|
-
closed: boolean;
|
|
87
|
-
currentPauseStart: number;
|
|
88
|
-
pauseCumulative: BN;
|
|
89
|
-
lastRateChangeTime: number;
|
|
90
|
-
fundsUnlockedAtLastRateChange: BN;
|
|
91
|
-
unlocked(currentTimestamp: number): BN;
|
|
92
|
-
}
|
|
93
49
|
export declare class Contract implements Stream {
|
|
94
50
|
magic: number;
|
|
95
51
|
version: number;
|
package/dist/aptos/types.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
15
|
};
|
|
@@ -54,7 +65,7 @@ var Contract = /** @class */ (function () {
|
|
|
54
65
|
this.fundsUnlockedAtLastRateChange = new bn_js_1.default(stream.funds_unlocked_at_last_rate_change);
|
|
55
66
|
}
|
|
56
67
|
Contract.prototype.unlocked = function (currentTimestamp) {
|
|
57
|
-
return (0, contractUtils_1.calculateUnlockedAmount)(
|
|
68
|
+
return (0, contractUtils_1.calculateUnlockedAmount)(__assign(__assign({}, this), { currentTimestamp: currentTimestamp }));
|
|
58
69
|
};
|
|
59
70
|
Contract.prototype.remaining = function (decimals) {
|
|
60
71
|
return (0, utils_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Stream } from "
|
|
2
|
-
import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData, IUpdateData, ITransactionResult, IMultiTransactionResult, ICreateResult, IGetAllData } from "./types";
|
|
1
|
+
import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData, IUpdateData, ITransactionResult, IMultiTransactionResult, ICreateResult, IGetAllData, Stream } from "./types";
|
|
3
2
|
export declare abstract class BaseStreamClient {
|
|
4
3
|
protected abstract create(streamData: ICreateStreamData, chainSpecificParams: any): Promise<ICreateResult>;
|
|
5
4
|
protected abstract createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: any): Promise<IMultiTransactionResult>;
|