@streamflow/stream 7.0.0-alpha.1 → 7.0.0-alpha.10

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.
Files changed (64) hide show
  1. package/README.md +65 -68
  2. package/dist/cjs/__tests__/aptos/streamClient.spec.js +83 -134
  3. package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +9 -9
  4. package/dist/cjs/aptos/StreamClient.js +162 -367
  5. package/dist/cjs/aptos/constants.js +7 -8
  6. package/dist/cjs/aptos/index.js +3 -3
  7. package/dist/cjs/aptos/types.js +32 -41
  8. package/dist/cjs/aptos/utils.js +4 -4
  9. package/dist/cjs/aptos/wallet.js +20 -75
  10. package/dist/cjs/common/BaseStreamClient.js +11 -59
  11. package/dist/cjs/common/GenericStreamClient.js +46 -72
  12. package/dist/cjs/common/constants.js +2 -2
  13. package/dist/cjs/common/contractUtils.js +16 -17
  14. package/dist/cjs/common/utils.js +34 -84
  15. package/dist/cjs/evm/StreamClient.js +198 -456
  16. package/dist/cjs/evm/constants.js +19 -20
  17. package/dist/cjs/evm/types.js +25 -34
  18. package/dist/cjs/evm/utils.js +2 -2
  19. package/dist/cjs/index.js +10 -10
  20. package/dist/cjs/solana/StreamClient.js +608 -1090
  21. package/dist/cjs/solana/constants.js +16 -11
  22. package/dist/cjs/solana/instructions.js +76 -80
  23. package/dist/cjs/solana/layout.js +7 -8
  24. package/dist/cjs/solana/types.js +15 -25
  25. package/dist/cjs/solana/utils.js +77 -154
  26. package/dist/cjs/sui/StreamClient.js +325 -571
  27. package/dist/cjs/sui/constants.js +19 -20
  28. package/dist/cjs/sui/types.js +28 -62
  29. package/dist/cjs/sui/utils.js +7 -7
  30. package/dist/cjs/sui/wallet.js +13 -63
  31. package/dist/esm/__tests__/aptos/streamClient.spec.js +4 -4
  32. package/dist/esm/aptos/index.d.ts +3 -3
  33. package/dist/esm/aptos/index.js +3 -3
  34. package/dist/esm/aptos/types.d.ts +12 -12
  35. package/dist/esm/aptos/types.js +13 -13
  36. package/dist/esm/common/GenericStreamClient.d.ts +4 -4
  37. package/dist/esm/common/GenericStreamClient.js +4 -4
  38. package/dist/esm/common/constants.d.ts +2 -2
  39. package/dist/esm/common/constants.js +2 -2
  40. package/dist/esm/common/contractUtils.d.ts +14 -14
  41. package/dist/esm/common/contractUtils.js +6 -6
  42. package/dist/esm/common/types.d.ts +19 -19
  43. package/dist/esm/common/utils.d.ts +11 -11
  44. package/dist/esm/common/utils.js +16 -19
  45. package/dist/esm/evm/StreamClient.d.ts +2 -2
  46. package/dist/esm/evm/StreamClient.js +7 -7
  47. package/dist/esm/evm/types.d.ts +37 -37
  48. package/dist/esm/evm/types.js +13 -13
  49. package/dist/esm/index.d.ts +9 -9
  50. package/dist/esm/index.js +9 -9
  51. package/dist/esm/solana/StreamClient.d.ts +3 -1
  52. package/dist/esm/solana/StreamClient.js +36 -20
  53. package/dist/esm/solana/constants.d.ts +3 -0
  54. package/dist/esm/solana/constants.js +6 -0
  55. package/dist/esm/solana/instructions.d.ts +17 -17
  56. package/dist/esm/solana/instructions.js +19 -18
  57. package/dist/esm/solana/types.d.ts +41 -36
  58. package/dist/esm/solana/types.js +2 -2
  59. package/dist/esm/solana/utils.d.ts +2 -0
  60. package/dist/esm/solana/utils.js +32 -26
  61. package/dist/esm/sui/StreamClient.js +1 -1
  62. package/dist/esm/sui/types.d.ts +12 -12
  63. package/dist/esm/sui/types.js +13 -13
  64. 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 { BN } from "bn.js";
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
- Types.IChain.Ethereum,
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
- Types.IChain.Polygon,
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
- Types.IChain.BNB,
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, Types } from "@streamflow/stream";
105
+ import { GenericStreamClient } from "@streamflow/stream";
125
106
 
126
107
  const client =
127
108
  new GenericStreamClient<Types.IChain.Solana>({
128
- chain: Types.IChain.Solana, // Blockchain
109
+ chain: IChain.Solana, // Blockchain
129
110
  clusterUrl: "https://api.mainnet-beta.solana.com", // RPC cluster URL
130
- cluster: Types.ICluster.Mainnet, // (optional) (default: Mainnet)
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: getBN(100, 9), // depositing 100 tokens with 9 decimals mint.
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: new BN(10), // Amount unlocked at the "cliff" timestamp.
150
- amountPerPeriod: getBN(5, 9), // Release rate: how many tokens are unlocked per each period.
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: null, // (optional) Partner's wallet address (string | null).
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] Wether Stream or Vesting should be paid with Solana native token or not
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: getBN(100, 9), // depositing 100 tokens with 9 decimals mint.
172
+ amount: getScaledBgNumber(100, 9), // depositing 100 tokens with 9 decimals mint.
192
173
  name: "January Payroll", // The stream name/subject.
193
- cliffAmount: getBN(10, 9), // amount released on cliff for this recipient
194
- amountPerPeriod: getBN(1, 9), //amount released every specified period epoch
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 createStreamParams: Types.ICreateMultipleStreamData = {
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: null, // (optional) Partner's wallet address (string | null).
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 `Types.ICreateResult` object (`createdMultiple` returns an Array) that has the following structure
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 | Types.TransactionPayload)[];
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: getBN(100, 9), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
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: Types.ITopUpData = {
286
- id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be topped up.
287
- amount: getBN(100, 9), // Specified amount to topup (increases deposited 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: Types.ITransferData = {
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: Types.ICancelData = {
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: Types.IUpdateData = {
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: getBN(10, 9), // [optional], allows to update release amount effective on next unlock
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: Types.IGetOneData = {
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); // bn amount unlocked at the tsInSeconds
428
- console.log(getNumberFromBN(unlocked, 9));
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; // bn amount withdrawn already
440
- console.log(getNumberFromBN(wihtdrawn, 9));
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: Types.IGetAllData = {
429
+ const data: IGetAllData = {
449
430
  address: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99",
450
- type: Types.StreamType.All,
451
- direction: Types.StreamDirection.All,
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 BN amounts are denominated in their smallest units.**
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 `new BN(1_000_000_000)` is used.
496
+ And `BigNumber(1_000_000_000)` is used.
500
497
 
501
- Use `getBN` and `getNumberFromBN` utility functions for conversions between `BN` and `Number` types.
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
- var bn_js_1 = require("bn.js");
54
- var vitest_1 = require("vitest");
55
- var StreamClient_js_1 = __importDefault(require("../../aptos/StreamClient.js"));
56
- var types_js_1 = require("../../common/types.js");
57
- (0, vitest_1.describe)("AptosStreamClient", function () {
58
- (0, vitest_1.describe)("init", function () {
59
- (0, vitest_1.test)("should successfully create AptosStreamInstance", function () {
60
- var instance = new StreamClient_js_1.default(types_js_1.ICluster.Devnet);
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", function () {
64
- var pid = "PID";
65
- var gas = "30";
66
- var instance = new StreamClient_js_1.default("https://cluster", types_js_1.ICluster.Devnet, gas, pid);
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", function () {
72
- var pid = "PID";
73
- var gas = "30";
74
- var instance = new StreamClient_js_1.default("https://cluster", types_js_1.ICluster.Devnet, gas, pid);
75
- (0, vitest_1.beforeEach)(function () {
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", function () { return __awaiter(void 0, void 0, void 0, function () {
79
- var mockSigner, mockWallet, mockRecipient, mockData, mockReturn, result, callParam, args;
80
- return __generator(this, function (_a) {
81
- switch (_a.label) {
82
- case 0:
83
- mockSigner = vitest_1.vi.fn();
84
- mockWallet = {
85
- signAndSubmitTransaction: mockSigner,
86
- account: { address: "" },
87
- };
88
- mockRecipient = {
89
- recipient: "0xtest",
90
- amount: new bn_js_1.BN(1000),
91
- name: "test name",
92
- cliffAmount: new bn_js_1.BN(1),
93
- amountPerPeriod: new bn_js_1.BN(1),
94
- };
95
- mockData = {
96
- period: 100,
97
- start: 10,
98
- cliff: 12,
99
- cancelableBySender: true,
100
- cancelableByRecipient: false,
101
- transferableBySender: false,
102
- transferableByRecipient: true,
103
- canTopup: true,
104
- automaticWithdrawal: false,
105
- withdrawalFrequency: 10,
106
- tokenId: "0xtest::token::Token",
107
- canPause: false,
108
- canUpdateRate: false,
109
- };
110
- mockReturn = "hash";
111
- mockSigner.mockResolvedValue({ hash: mockReturn });
112
- return [4 /*yield*/, instance.create(__assign(__assign({}, mockData), mockRecipient), { senderWallet: mockWallet })];
113
- case 1:
114
- result = _a.sent();
115
- // Assert
116
- (0, vitest_1.expect)(mockSigner).toHaveBeenCalledTimes(1);
117
- callParam = mockSigner.mock.calls[0][0];
118
- args = callParam.arguments;
119
- delete callParam.arguments;
120
- args.shift();
121
- (0, vitest_1.expect)(args).toEqual([
122
- mockRecipient.amount.toString(),
123
- 100,
124
- mockRecipient.amountPerPeriod.toString(),
125
- 10,
126
- mockRecipient.cliffAmount.toString(),
127
- true,
128
- false,
129
- false,
130
- true,
131
- true,
132
- false,
133
- false,
134
- false,
135
- 10,
136
- "test name",
137
- "0xtest",
138
- ]);
139
- (0, vitest_1.expect)(callParam).toEqual({
140
- function: "PID::protocol::create",
141
- type: "create",
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
- var ethers_1 = require("ethers");
7
- var vitest_1 = require("vitest");
8
- var index_js_1 = require("../../index.js");
9
- var GenericStreamClient_js_1 = __importDefault(require("../../common/GenericStreamClient.js"));
10
- var types_js_1 = require("../../common/types.js");
11
- (0, vitest_1.describe)("GenericStreamClient", function () {
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)", function (config) {
39
- (0, vitest_1.test)("should successfully create GenericStreamClient instance", function () {
40
- var instance = new GenericStreamClient_js_1.default(config);
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
  });