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