@streamflow/stream 7.0.0-alpha.2 → 7.0.0-alpha.20
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 +70 -67
- package/dist/cjs/__tests__/aptos/streamClient.spec.js +83 -134
- package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +9 -9
- package/dist/cjs/aptos/StreamClient.js +162 -367
- package/dist/cjs/aptos/constants.js +7 -8
- package/dist/cjs/aptos/index.js +3 -3
- package/dist/cjs/aptos/types.js +28 -37
- package/dist/cjs/aptos/utils.js +4 -4
- package/dist/cjs/aptos/wallet.js +20 -75
- package/dist/cjs/common/BaseStreamClient.js +11 -59
- package/dist/cjs/common/GenericStreamClient.js +46 -72
- package/dist/cjs/common/constants.js +4 -3
- package/dist/cjs/common/contractUtils.js +33 -18
- package/dist/cjs/common/types.js +30 -1
- package/dist/cjs/common/utils.js +38 -80
- package/dist/cjs/evm/StreamClient.js +198 -456
- package/dist/cjs/evm/constants.js +19 -20
- package/dist/cjs/evm/types.js +25 -34
- package/dist/cjs/evm/utils.js +2 -2
- package/dist/cjs/index.js +10 -10
- package/dist/cjs/solana/StreamClient.js +759 -1090
- package/dist/cjs/solana/constants.js +44 -11
- package/dist/cjs/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.js +2 -0
- package/dist/cjs/solana/index.js +2 -1
- package/dist/cjs/solana/instructions.js +75 -81
- package/dist/cjs/solana/layout.js +7 -8
- package/dist/cjs/solana/lib/derive-accounts.js +17 -0
- package/dist/cjs/solana/lib/utils.js +127 -0
- package/dist/cjs/solana/types.js +40 -27
- package/dist/cjs/sui/StreamClient.js +325 -571
- package/dist/cjs/sui/constants.js +19 -20
- package/dist/cjs/sui/types.js +28 -62
- package/dist/cjs/sui/utils.js +7 -7
- package/dist/cjs/sui/wallet.js +13 -63
- package/dist/esm/__tests__/aptos/streamClient.spec.js +4 -4
- package/dist/esm/aptos/index.d.ts +3 -3
- package/dist/esm/aptos/index.js +3 -3
- package/dist/esm/aptos/types.d.ts +14 -14
- package/dist/esm/aptos/types.js +13 -13
- package/dist/esm/common/GenericStreamClient.d.ts +4 -4
- package/dist/esm/common/GenericStreamClient.js +4 -4
- package/dist/esm/common/constants.d.ts +3 -2
- package/dist/esm/common/constants.js +3 -2
- package/dist/esm/common/contractUtils.d.ts +18 -15
- package/dist/esm/common/contractUtils.js +19 -6
- package/dist/esm/common/types.d.ts +112 -57
- package/dist/esm/common/types.js +29 -0
- package/dist/esm/common/utils.d.ts +11 -11
- package/dist/esm/common/utils.js +19 -16
- package/dist/esm/evm/StreamClient.d.ts +2 -2
- package/dist/esm/evm/StreamClient.js +7 -7
- package/dist/esm/evm/types.d.ts +14 -14
- package/dist/esm/evm/types.js +13 -13
- package/dist/esm/index.d.ts +9 -9
- package/dist/esm/index.js +9 -9
- package/dist/esm/solana/StreamClient.d.ts +24 -16
- package/dist/esm/solana/StreamClient.js +324 -156
- package/dist/esm/solana/constants.d.ts +17 -0
- package/dist/esm/solana/constants.js +35 -1
- package/dist/esm/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.d.ts +1272 -0
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js +1 -0
- package/dist/esm/solana/index.d.ts +2 -1
- package/dist/esm/solana/index.js +2 -1
- package/dist/esm/solana/instructions.d.ts +17 -17
- package/dist/esm/solana/instructions.js +18 -19
- package/dist/esm/solana/lib/derive-accounts.d.ts +4 -0
- package/dist/esm/solana/lib/derive-accounts.js +11 -0
- package/dist/esm/solana/{utils.d.ts → lib/utils.d.ts} +1 -3
- package/dist/esm/solana/{utils.js → lib/utils.js} +28 -34
- package/dist/esm/solana/types.d.ts +72 -39
- package/dist/esm/solana/types.js +32 -4
- package/dist/esm/sui/StreamClient.js +1 -1
- package/dist/esm/sui/types.d.ts +14 -14
- package/dist/esm/sui/types.js +13 -13
- package/package.json +12 -10
- package/dist/cjs/solana/utils.js +0 -222
package/README.md
CHANGED
|
@@ -22,7 +22,8 @@ API Documentation available here: [docs site →](https://streamflow-finance.git
|
|
|
22
22
|
Most common imports:
|
|
23
23
|
|
|
24
24
|
```javascript
|
|
25
|
-
import {
|
|
25
|
+
import { BN } from "bn.js";
|
|
26
|
+
import { GenericStreamClient, getBN, getNumberFromBN } from "@streamflow/stream";
|
|
26
27
|
```
|
|
27
28
|
|
|
28
29
|
_Check the SDK for other types and utility functions._
|
|
@@ -34,10 +35,7 @@ Before creating and manipulating streams chain specific or generic StreamClient
|
|
|
34
35
|
### Solana
|
|
35
36
|
|
|
36
37
|
```javascript
|
|
37
|
-
import {
|
|
38
|
-
StreamflowSolana,
|
|
39
|
-
Types,
|
|
40
|
-
} from "@streamflow/stream";
|
|
38
|
+
import { StreamflowSolana } from "@streamflow/stream";
|
|
41
39
|
|
|
42
40
|
const solanaClient = new StreamflowSolana.SolanaStreamClient(
|
|
43
41
|
"https://api.mainnet-beta.solana.com"
|
|
@@ -47,10 +45,7 @@ const solanaClient = new StreamflowSolana.SolanaStreamClient(
|
|
|
47
45
|
### Aptos
|
|
48
46
|
|
|
49
47
|
```javascript
|
|
50
|
-
import {
|
|
51
|
-
StreamflowAptos,
|
|
52
|
-
Types,
|
|
53
|
-
} from "@streamflow/stream";
|
|
48
|
+
import { StreamflowAptos } from "@streamflow/stream";
|
|
54
49
|
|
|
55
50
|
const aptosClient = new StreamflowAptos.AptosStreamClient(
|
|
56
51
|
"https://fullnode.mainnet.aptoslabs.com/v1"
|
|
@@ -60,14 +55,11 @@ const aptosClient = new StreamflowAptos.AptosStreamClient(
|
|
|
60
55
|
### Ethereum
|
|
61
56
|
|
|
62
57
|
```javascript
|
|
63
|
-
import {
|
|
64
|
-
StreamflowEVM,
|
|
65
|
-
Types,
|
|
66
|
-
} from "@streamflow/stream";
|
|
58
|
+
import { StreamflowEVM } from "@streamflow/stream";
|
|
67
59
|
|
|
68
60
|
const ethereumClient = new StreamflowEVM.EvmStreamClient(
|
|
69
61
|
"YOUR_ETHEREUM_NODE_URL",
|
|
70
|
-
|
|
62
|
+
IChain.Ethereum,
|
|
71
63
|
signer // will be sender in a stream and authority for all stream related transactions
|
|
72
64
|
);
|
|
73
65
|
```
|
|
@@ -75,14 +67,11 @@ const ethereumClient = new StreamflowEVM.EvmStreamClient(
|
|
|
75
67
|
### Polygon
|
|
76
68
|
|
|
77
69
|
```javascript
|
|
78
|
-
import {
|
|
79
|
-
StreamflowEVM,
|
|
80
|
-
Types,
|
|
81
|
-
} from "@streamflow/stream";
|
|
70
|
+
import { StreamflowEVM } from "@streamflow/stream";
|
|
82
71
|
|
|
83
72
|
const polygonClient = new StreamflowEVM.EvmStreamClient(
|
|
84
73
|
"YOUR_POLYGON_NODE_URL",
|
|
85
|
-
|
|
74
|
+
IChain.Polygon,
|
|
86
75
|
signer // will be sender in a stream and authority for all stream related transactions
|
|
87
76
|
);
|
|
88
77
|
```
|
|
@@ -90,14 +79,11 @@ const polygonClient = new StreamflowEVM.EvmStreamClient(
|
|
|
90
79
|
### BNB
|
|
91
80
|
|
|
92
81
|
```javascript
|
|
93
|
-
import {
|
|
94
|
-
StreamflowEVM,
|
|
95
|
-
Types,
|
|
96
|
-
} from "@streamflow/stream";
|
|
82
|
+
import { StreamflowEVM } from "@streamflow/stream";
|
|
97
83
|
|
|
98
84
|
const bnbClient = new StreamflowEVM.EvmStreamClient(
|
|
99
85
|
"https://bsc-dataseed1.binance.org/",
|
|
100
|
-
|
|
86
|
+
IChain.BNB,
|
|
101
87
|
signer // will be sender in a stream and authority for all stream related transactions
|
|
102
88
|
);
|
|
103
89
|
```
|
|
@@ -105,10 +91,7 @@ const bnbClient = new StreamflowEVM.EvmStreamClient(
|
|
|
105
91
|
### Sui
|
|
106
92
|
|
|
107
93
|
```javascript
|
|
108
|
-
import {
|
|
109
|
-
StreamflowSui,
|
|
110
|
-
Types,
|
|
111
|
-
} from "@streamflow/stream";
|
|
94
|
+
import { StreamflowSui } from "@streamflow/stream";
|
|
112
95
|
|
|
113
96
|
const suiClient = new StreamflowSui.SuiStreamClient(
|
|
114
97
|
"https://fullnode.testnet.sui.io:443"
|
|
@@ -120,13 +103,13 @@ const suiClient = new StreamflowSui.SuiStreamClient(
|
|
|
120
103
|
GenericStreamClient provides isomorphic interface to work with streams agnostic of chain.
|
|
121
104
|
|
|
122
105
|
```javascript
|
|
123
|
-
import { GenericStreamClient
|
|
106
|
+
import { GenericStreamClient } from "@streamflow/stream";
|
|
124
107
|
|
|
125
108
|
const client =
|
|
126
109
|
new GenericStreamClient<Types.IChain.Solana>({
|
|
127
|
-
chain:
|
|
110
|
+
chain: IChain.Solana, // Blockchain
|
|
128
111
|
clusterUrl: "https://api.mainnet-beta.solana.com", // RPC cluster URL
|
|
129
|
-
cluster:
|
|
112
|
+
cluster: ICluster.Mainnet, // (optional) (default: Mainnet)
|
|
130
113
|
// ...rest chain specific params e.g. commitment for Solana
|
|
131
114
|
});
|
|
132
115
|
```
|
|
@@ -142,13 +125,13 @@ const createStreamParams: Types.ICreateStreamData = {
|
|
|
142
125
|
recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Recipient address.
|
|
143
126
|
tokenId: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // Token mint address.
|
|
144
127
|
start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
|
|
145
|
-
amount:
|
|
128
|
+
amount: getBN(100, 9), // depositing 100 tokens with 9 decimals mint.
|
|
146
129
|
period: 1, // Time step (period) in seconds per which the unlocking occurs.
|
|
147
130
|
cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds.
|
|
148
|
-
cliffAmount: 10, // Amount unlocked at the "cliff" timestamp.
|
|
149
|
-
amountPerPeriod:
|
|
131
|
+
cliffAmount: new BN(10), // Amount unlocked at the "cliff" timestamp.
|
|
132
|
+
amountPerPeriod: getBN(5, 9), // Release rate: how many tokens are unlocked per each period.
|
|
150
133
|
name: "Transfer to Jane Doe.", // The stream name or subject.
|
|
151
|
-
canTopup: false, // setting to FALSE will effectively create a vesting contract.
|
|
134
|
+
canTopup: false, // Whether additional tokens can be deposited after creation, setting to FALSE will effectively create a vesting contract.
|
|
152
135
|
canUpdateRate: false, // settings to TRUE allows sender to update amountPerPeriod
|
|
153
136
|
cancelableBySender: true, // Whether or not sender can cancel the stream.
|
|
154
137
|
cancelableByRecipient: false, // Whether or not recipient can cancel the stream.
|
|
@@ -156,12 +139,12 @@ const createStreamParams: Types.ICreateStreamData = {
|
|
|
156
139
|
transferableByRecipient: false, // Whether or not recipient can transfer the stream.
|
|
157
140
|
automaticWithdrawal: true, // Whether or not a 3rd party (e.g. cron job, "cranker") can initiate a token withdraw/transfer.
|
|
158
141
|
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.
|
|
159
|
-
partner:
|
|
142
|
+
partner: undefined, // (optional) Partner's wallet address (string | undefined).
|
|
160
143
|
};
|
|
161
144
|
|
|
162
145
|
const solanaParams = {
|
|
163
146
|
sender: wallet, // SignerWalletAdapter or Keypair of Sender account
|
|
164
|
-
isNative: false // [optional] [WILL CREATE A wSOL STREAM]
|
|
147
|
+
isNative: false // [optional] [WILL CREATE A wSOL STREAM] Whether Stream or Vesting should be paid with Solana native token or not
|
|
165
148
|
};
|
|
166
149
|
|
|
167
150
|
const aptosParams = {
|
|
@@ -187,13 +170,13 @@ try {
|
|
|
187
170
|
const recipients = [
|
|
188
171
|
{
|
|
189
172
|
recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Solana recipient address.
|
|
190
|
-
amount:
|
|
173
|
+
amount: getBN(100, 9), // depositing 100 tokens with 9 decimals mint.
|
|
191
174
|
name: "January Payroll", // The stream name/subject.
|
|
192
|
-
cliffAmount:
|
|
193
|
-
amountPerPeriod:
|
|
175
|
+
cliffAmount: getBN(10, 9), // amount released on cliff for this recipient
|
|
176
|
+
amountPerPeriod: getBN(1, 9), //amount released every specified period epoch
|
|
194
177
|
},
|
|
195
178
|
];
|
|
196
|
-
const
|
|
179
|
+
const createMultiStreamsParams: ICreateMultipleStreamData = {
|
|
197
180
|
recipients: recipients, // Solana recipient address.
|
|
198
181
|
tokenId: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // SPL Token mint.
|
|
199
182
|
start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
|
|
@@ -206,7 +189,7 @@ const createStreamParams: Types.ICreateMultipleStreamData = {
|
|
|
206
189
|
transferableByRecipient: false, // Whether or not recipient can transfer the stream.
|
|
207
190
|
automaticWithdrawal: true, // Whether or not a 3rd party (e.g. cron job, "cranker") can initiate a token withdraw/transfer.
|
|
208
191
|
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.
|
|
209
|
-
partner:
|
|
192
|
+
partner: undefined, // (optional) Partner's wallet address (string | undefined).
|
|
210
193
|
};
|
|
211
194
|
|
|
212
195
|
const solanaParams = {
|
|
@@ -235,11 +218,11 @@ Please note that transaction fees for the scheduled transfers are paid upfront b
|
|
|
235
218
|
|
|
236
219
|
## Identifying created contracts (streams or vesting)
|
|
237
220
|
|
|
238
|
-
All Stream Clients return `
|
|
221
|
+
All Stream Clients return `ICreateResult` object (`createMultiple` returns an Array) that has the following structure
|
|
239
222
|
|
|
240
223
|
```javascript
|
|
241
224
|
interface ICreateResult {
|
|
242
|
-
ixs: (TransactionInstruction |
|
|
225
|
+
ixs: (TransactionInstruction | TransactionPayload)[];
|
|
243
226
|
txId: string;
|
|
244
227
|
metadataId: MetadataId;
|
|
245
228
|
}
|
|
@@ -251,8 +234,8 @@ interface ICreateResult {
|
|
|
251
234
|
|
|
252
235
|
```javascript
|
|
253
236
|
const withdrawStreamParams: Types.IWithdrawData = {
|
|
254
|
-
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be withdrawn from.
|
|
255
|
-
amount:
|
|
237
|
+
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier (address) of a stream to be withdrawn from.
|
|
238
|
+
amount: getBN(100, 9), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
|
|
256
239
|
};
|
|
257
240
|
|
|
258
241
|
const solanaParams = {
|
|
@@ -281,14 +264,14 @@ try {
|
|
|
281
264
|
## Topup stream
|
|
282
265
|
|
|
283
266
|
```javascript
|
|
284
|
-
const topupStreamParams:
|
|
285
|
-
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be topped up.
|
|
286
|
-
amount:
|
|
267
|
+
const topupStreamParams: ITopUpData = {
|
|
268
|
+
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier (address) of a stream to be topped up.
|
|
269
|
+
amount: getBN(100, 9), // Specified amount to topup (increases deposited amount).
|
|
287
270
|
};
|
|
288
271
|
|
|
289
272
|
const solanaParams = {
|
|
290
273
|
invoker: wallet, // SignerWalletAdapter or Keypair signing the transaction
|
|
291
|
-
isNative: // [ONLY FOR wSOL STREAMS] [optional] Wether topup is with Native Solanas
|
|
274
|
+
isNative: true // [ONLY FOR wSOL STREAMS] [optional] Wether topup is with Native Solanas
|
|
292
275
|
};
|
|
293
276
|
|
|
294
277
|
const aptosParams = {
|
|
@@ -313,9 +296,9 @@ try {
|
|
|
313
296
|
## Transfer stream to another recipient
|
|
314
297
|
|
|
315
298
|
```javascript
|
|
316
|
-
const data:
|
|
317
|
-
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
|
|
318
|
-
newRecipient: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99", // Identifier of a stream to be transferred.
|
|
299
|
+
const data: ITransferData = {
|
|
300
|
+
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier (address) of the stream to be transferred
|
|
301
|
+
newRecipient: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99", // Identifier (address) of a stream to be transferred.
|
|
319
302
|
};
|
|
320
303
|
|
|
321
304
|
const solanaParams = {
|
|
@@ -344,7 +327,7 @@ try {
|
|
|
344
327
|
## Cancel stream
|
|
345
328
|
|
|
346
329
|
```javascript
|
|
347
|
-
const cancelStreamParams:
|
|
330
|
+
const cancelStreamParams: ICancelData = {
|
|
348
331
|
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be canceled.
|
|
349
332
|
};
|
|
350
333
|
|
|
@@ -374,11 +357,11 @@ try {
|
|
|
374
357
|
## Update a stream
|
|
375
358
|
|
|
376
359
|
```javascript
|
|
377
|
-
const updateStreamParams:
|
|
360
|
+
const updateStreamParams: IUpdateData = {
|
|
378
361
|
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to update.
|
|
379
362
|
enableAutomaticWithdrawal: true, // [optional], allows to enable AW if it wasn't, disable is not possible
|
|
380
363
|
withdrawFrequency: 60, // [optional], allows to update withdrawal frequency, may result in additional AW fees
|
|
381
|
-
amountPerPeriod:
|
|
364
|
+
amountPerPeriod: getBN(10, 9), // [optional], allows to update release amount effective on next unlock
|
|
382
365
|
}
|
|
383
366
|
|
|
384
367
|
const solanaParams = {
|
|
@@ -405,7 +388,7 @@ try {
|
|
|
405
388
|
## Get one stream by its ID
|
|
406
389
|
|
|
407
390
|
```javascript
|
|
408
|
-
const data:
|
|
391
|
+
const data: IGetOneData = {
|
|
409
392
|
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream
|
|
410
393
|
};
|
|
411
394
|
|
|
@@ -423,8 +406,8 @@ const stream = await client.getOne({
|
|
|
423
406
|
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
|
|
424
407
|
});
|
|
425
408
|
|
|
426
|
-
const unlocked = stream.unlocked(tsInSeconds); //
|
|
427
|
-
console.log(
|
|
409
|
+
const unlocked = stream.unlocked(tsInSeconds); // BN amount unlocked at the tsInSeconds
|
|
410
|
+
console.log(getNumberFromBN(unlocked, 9));
|
|
428
411
|
```
|
|
429
412
|
|
|
430
413
|
- Note: unlocked amount is determined based on configuration set on creation, no dynamic data is involved.
|
|
@@ -435,8 +418,8 @@ console.log(getNumberFromBigNumber(unlocked, 9));
|
|
|
435
418
|
const stream = await client.getOne({
|
|
436
419
|
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
|
|
437
420
|
});
|
|
438
|
-
const withdrawn = stream.withdrawnAmount; //
|
|
439
|
-
console.log(
|
|
421
|
+
const withdrawn = stream.withdrawnAmount; // bn amount withdrawn already
|
|
422
|
+
console.log(getNumberFromBN(wihtdrawn, 9));
|
|
440
423
|
const remaining = stream.remaining(9); // amount of remaining funds
|
|
441
424
|
console.log(remaining);
|
|
442
425
|
```
|
|
@@ -444,10 +427,10 @@ console.log(remaining);
|
|
|
444
427
|
## Get multiple streams for a specific wallet address
|
|
445
428
|
|
|
446
429
|
```javascript
|
|
447
|
-
const data:
|
|
430
|
+
const data: IGetAllData = {
|
|
448
431
|
address: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99",
|
|
449
|
-
type:
|
|
450
|
-
direction:
|
|
432
|
+
type: StreamType.All, // StreamType.Vesting, StreamType.Lock, StreamType.Payment
|
|
433
|
+
direction: StreamDirection.All, // StreamDirection.Outgoing, StreamDirection.Incoming
|
|
451
434
|
};
|
|
452
435
|
|
|
453
436
|
try {
|
|
@@ -457,6 +440,22 @@ try {
|
|
|
457
440
|
}
|
|
458
441
|
```
|
|
459
442
|
|
|
443
|
+
## Search Solana Streams
|
|
444
|
+
|
|
445
|
+
Solana RPC is pretty rich in what data it can allow to filter by, so we expose a separate `searchStreams` method on `SolanaStreamClient`:
|
|
446
|
+
|
|
447
|
+
```javascript
|
|
448
|
+
// All parameters are optional, so in theory you can just fetch all Streams
|
|
449
|
+
const params = {
|
|
450
|
+
mint: "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263",
|
|
451
|
+
sender: "AKp8CxGbhsrsEsCFUtx7e3MWyW7SWi1uuSqv6N4BEohJ",
|
|
452
|
+
recipient: "9mqcpDjCHCPmttJp2t477oJ71NdAvJeSus8BcCrrvwy5",
|
|
453
|
+
}
|
|
454
|
+
// nativeStreamClient is exposed on a GenericStreamClient, you can also use SolanaStreamClient directly
|
|
455
|
+
// Return an Array of objects {publicKey: PublicKey, account: Stream}
|
|
456
|
+
const streams = await client.nativeStreamClient.searchStreams(params);
|
|
457
|
+
```
|
|
458
|
+
|
|
460
459
|
## Handling errors
|
|
461
460
|
|
|
462
461
|
`GenericStreamClient` wraps all errors when making on-chain calls with `ContractError` error class:
|
|
@@ -491,10 +490,14 @@ Streamflow protocol program IDs
|
|
|
491
490
|
| Testnet | 0xf1916c119a6c917d4b36f96ffc0443930745789f3126a716e05a62223c48993a |
|
|
492
491
|
| Mainnet | 0xa283fd6b45f1103176e7ae27e870c89df7c8783b15345e2b13faa81ec25c4fa6 |
|
|
493
492
|
|
|
494
|
-
**All
|
|
493
|
+
**All BN amounts are denominated in their smallest units.**
|
|
495
494
|
|
|
496
495
|
E.g, if the amount is 1 SOL than this amount in lamports is `1000 \* 10^9 = 1_000_000_000.`
|
|
497
496
|
|
|
498
|
-
And `
|
|
497
|
+
And `new BN(1_000_000_000)` is used.
|
|
498
|
+
|
|
499
|
+
Use `getBN` and `getNumberFromBN` utility functions for conversions between `BN` and `Number` types.
|
|
500
|
+
|
|
501
|
+
`getBN(1, 9)` is equal to `new BN(1_000_000_000)`
|
|
499
502
|
|
|
500
|
-
|
|
503
|
+
`getNumberFromBN(new BN(1_000_000_000), 9)` will return 1
|
|
@@ -1,151 +1,100 @@
|
|
|
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
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
4
|
};
|
|
52
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
(0, vitest_1.describe)("AptosStreamClient",
|
|
58
|
-
(0, vitest_1.describe)("init",
|
|
59
|
-
(0, vitest_1.test)("should successfully create AptosStreamInstance",
|
|
60
|
-
|
|
6
|
+
const bn_js_1 = require("bn.js");
|
|
7
|
+
const vitest_1 = require("vitest");
|
|
8
|
+
const StreamClient_js_1 = __importDefault(require("../../aptos/StreamClient.js"));
|
|
9
|
+
const types_js_1 = require("../../common/types.js");
|
|
10
|
+
(0, vitest_1.describe)("AptosStreamClient", () => {
|
|
11
|
+
(0, vitest_1.describe)("init", () => {
|
|
12
|
+
(0, vitest_1.test)("should successfully create AptosStreamInstance", () => {
|
|
13
|
+
const instance = new StreamClient_js_1.default(types_js_1.ICluster.Devnet);
|
|
61
14
|
(0, vitest_1.expect)(instance).toBeInstanceOf(StreamClient_js_1.default);
|
|
62
15
|
});
|
|
63
|
-
(0, vitest_1.test)("should correctly set passed params",
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
16
|
+
(0, vitest_1.test)("should correctly set passed params", () => {
|
|
17
|
+
const pid = "PID";
|
|
18
|
+
const gas = "30";
|
|
19
|
+
const instance = new StreamClient_js_1.default("https://cluster", types_js_1.ICluster.Devnet, gas, pid);
|
|
67
20
|
(0, vitest_1.expect)(instance.getMaxGas()).toEqual({ max_gas_amount: gas });
|
|
68
21
|
(0, vitest_1.expect)(instance.getProgramId()).toBe(pid);
|
|
69
22
|
});
|
|
70
23
|
});
|
|
71
|
-
(0, vitest_1.describe)("create",
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
(0, vitest_1.beforeEach)(
|
|
24
|
+
(0, vitest_1.describe)("create", () => {
|
|
25
|
+
const pid = "PID";
|
|
26
|
+
const gas = "30";
|
|
27
|
+
let instance = new StreamClient_js_1.default("https://cluster", types_js_1.ICluster.Devnet, gas, pid);
|
|
28
|
+
(0, vitest_1.beforeEach)(() => {
|
|
76
29
|
instance = new StreamClient_js_1.default("https://cluster", types_js_1.ICluster.Devnet, gas, pid);
|
|
77
30
|
});
|
|
78
|
-
(0, vitest_1.test)("should create a stream with passed parameters",
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
type_arguments: ["0xtest::token::Token"],
|
|
143
|
-
});
|
|
144
|
-
(0, vitest_1.expect)(result.txId).toEqual(mockReturn);
|
|
145
|
-
return [2 /*return*/];
|
|
146
|
-
}
|
|
31
|
+
(0, vitest_1.test)("should create a stream with passed parameters", async () => {
|
|
32
|
+
// Arrange
|
|
33
|
+
const mockSigner = vitest_1.vi.fn();
|
|
34
|
+
const mockWallet = {
|
|
35
|
+
signAndSubmitTransaction: mockSigner,
|
|
36
|
+
account: { address: "" },
|
|
37
|
+
};
|
|
38
|
+
const mockRecipient = {
|
|
39
|
+
recipient: "0xtest",
|
|
40
|
+
amount: new bn_js_1.BN(1000),
|
|
41
|
+
name: "test name",
|
|
42
|
+
cliffAmount: new bn_js_1.BN(1),
|
|
43
|
+
amountPerPeriod: new bn_js_1.BN(1),
|
|
44
|
+
};
|
|
45
|
+
const mockData = {
|
|
46
|
+
period: 100,
|
|
47
|
+
start: 10,
|
|
48
|
+
cliff: 12,
|
|
49
|
+
cancelableBySender: true,
|
|
50
|
+
cancelableByRecipient: false,
|
|
51
|
+
transferableBySender: false,
|
|
52
|
+
transferableByRecipient: true,
|
|
53
|
+
canTopup: true,
|
|
54
|
+
automaticWithdrawal: false,
|
|
55
|
+
withdrawalFrequency: 10,
|
|
56
|
+
tokenId: "0xtest::token::Token",
|
|
57
|
+
canPause: false,
|
|
58
|
+
canUpdateRate: false,
|
|
59
|
+
};
|
|
60
|
+
const mockReturn = "hash";
|
|
61
|
+
mockSigner.mockResolvedValue({ hash: mockReturn });
|
|
62
|
+
// Act
|
|
63
|
+
const result = await instance.create({
|
|
64
|
+
...mockData,
|
|
65
|
+
...mockRecipient,
|
|
66
|
+
}, { senderWallet: mockWallet });
|
|
67
|
+
// Assert
|
|
68
|
+
(0, vitest_1.expect)(mockSigner).toHaveBeenCalledTimes(1);
|
|
69
|
+
const callParam = mockSigner.mock.calls[0][0];
|
|
70
|
+
const args = callParam.arguments;
|
|
71
|
+
delete callParam.arguments;
|
|
72
|
+
args.shift();
|
|
73
|
+
(0, vitest_1.expect)(args).toEqual([
|
|
74
|
+
mockRecipient.amount.toString(),
|
|
75
|
+
100,
|
|
76
|
+
mockRecipient.amountPerPeriod.toString(),
|
|
77
|
+
10,
|
|
78
|
+
mockRecipient.cliffAmount.toString(),
|
|
79
|
+
true,
|
|
80
|
+
false,
|
|
81
|
+
false,
|
|
82
|
+
true,
|
|
83
|
+
true,
|
|
84
|
+
false,
|
|
85
|
+
false,
|
|
86
|
+
false,
|
|
87
|
+
10,
|
|
88
|
+
"test name",
|
|
89
|
+
"0xtest",
|
|
90
|
+
]);
|
|
91
|
+
(0, vitest_1.expect)(callParam).toEqual({
|
|
92
|
+
function: "PID::protocol::create",
|
|
93
|
+
type: "create",
|
|
94
|
+
type_arguments: ["0xtest::token::Token"],
|
|
147
95
|
});
|
|
148
|
-
|
|
96
|
+
(0, vitest_1.expect)(result.txId).toEqual(mockReturn);
|
|
97
|
+
});
|
|
149
98
|
});
|
|
150
99
|
// describe("createMultiple", () => {
|
|
151
100
|
// });
|
|
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
(0, vitest_1.describe)("GenericStreamClient",
|
|
6
|
+
const ethers_1 = require("ethers");
|
|
7
|
+
const vitest_1 = require("vitest");
|
|
8
|
+
const index_js_1 = require("../../index.js");
|
|
9
|
+
const GenericStreamClient_js_1 = __importDefault(require("../../common/GenericStreamClient.js"));
|
|
10
|
+
const types_js_1 = require("../../common/types.js");
|
|
11
|
+
(0, vitest_1.describe)("GenericStreamClient", () => {
|
|
12
12
|
vitest_1.describe.each([
|
|
13
13
|
{
|
|
14
14
|
chain: types_js_1.IChain.Aptos,
|
|
@@ -35,9 +35,9 @@ var types_js_1 = require("../../common/types.js");
|
|
|
35
35
|
clusterUrl: "https://cluster",
|
|
36
36
|
expected: index_js_1.StreamflowSui.SuiStreamClient,
|
|
37
37
|
},
|
|
38
|
-
])(".init($chain)",
|
|
39
|
-
(0, vitest_1.test)("should successfully create GenericStreamClient instance",
|
|
40
|
-
|
|
38
|
+
])(".init($chain)", (config) => {
|
|
39
|
+
(0, vitest_1.test)("should successfully create GenericStreamClient instance", () => {
|
|
40
|
+
const instance = new GenericStreamClient_js_1.default(config);
|
|
41
41
|
(0, vitest_1.expect)(instance).toBeInstanceOf(GenericStreamClient_js_1.default);
|
|
42
42
|
(0, vitest_1.expect)(instance.nativeStreamClient).toBeInstanceOf(config.expected);
|
|
43
43
|
});
|