@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.
Files changed (78) hide show
  1. package/README.md +70 -67
  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 +28 -37
  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 +4 -3
  13. package/dist/cjs/common/contractUtils.js +33 -18
  14. package/dist/cjs/common/types.js +30 -1
  15. package/dist/cjs/common/utils.js +38 -80
  16. package/dist/cjs/evm/StreamClient.js +198 -456
  17. package/dist/cjs/evm/constants.js +19 -20
  18. package/dist/cjs/evm/types.js +25 -34
  19. package/dist/cjs/evm/utils.js +2 -2
  20. package/dist/cjs/index.js +10 -10
  21. package/dist/cjs/solana/StreamClient.js +759 -1090
  22. package/dist/cjs/solana/constants.js +44 -11
  23. package/dist/cjs/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
  24. package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.js +2 -0
  25. package/dist/cjs/solana/index.js +2 -1
  26. package/dist/cjs/solana/instructions.js +75 -81
  27. package/dist/cjs/solana/layout.js +7 -8
  28. package/dist/cjs/solana/lib/derive-accounts.js +17 -0
  29. package/dist/cjs/solana/lib/utils.js +127 -0
  30. package/dist/cjs/solana/types.js +40 -27
  31. package/dist/cjs/sui/StreamClient.js +325 -571
  32. package/dist/cjs/sui/constants.js +19 -20
  33. package/dist/cjs/sui/types.js +28 -62
  34. package/dist/cjs/sui/utils.js +7 -7
  35. package/dist/cjs/sui/wallet.js +13 -63
  36. package/dist/esm/__tests__/aptos/streamClient.spec.js +4 -4
  37. package/dist/esm/aptos/index.d.ts +3 -3
  38. package/dist/esm/aptos/index.js +3 -3
  39. package/dist/esm/aptos/types.d.ts +14 -14
  40. package/dist/esm/aptos/types.js +13 -13
  41. package/dist/esm/common/GenericStreamClient.d.ts +4 -4
  42. package/dist/esm/common/GenericStreamClient.js +4 -4
  43. package/dist/esm/common/constants.d.ts +3 -2
  44. package/dist/esm/common/constants.js +3 -2
  45. package/dist/esm/common/contractUtils.d.ts +18 -15
  46. package/dist/esm/common/contractUtils.js +19 -6
  47. package/dist/esm/common/types.d.ts +112 -57
  48. package/dist/esm/common/types.js +29 -0
  49. package/dist/esm/common/utils.d.ts +11 -11
  50. package/dist/esm/common/utils.js +19 -16
  51. package/dist/esm/evm/StreamClient.d.ts +2 -2
  52. package/dist/esm/evm/StreamClient.js +7 -7
  53. package/dist/esm/evm/types.d.ts +14 -14
  54. package/dist/esm/evm/types.js +13 -13
  55. package/dist/esm/index.d.ts +9 -9
  56. package/dist/esm/index.js +9 -9
  57. package/dist/esm/solana/StreamClient.d.ts +24 -16
  58. package/dist/esm/solana/StreamClient.js +324 -156
  59. package/dist/esm/solana/constants.d.ts +17 -0
  60. package/dist/esm/solana/constants.js +35 -1
  61. package/dist/esm/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
  62. package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.d.ts +1272 -0
  63. package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js +1 -0
  64. package/dist/esm/solana/index.d.ts +2 -1
  65. package/dist/esm/solana/index.js +2 -1
  66. package/dist/esm/solana/instructions.d.ts +17 -17
  67. package/dist/esm/solana/instructions.js +18 -19
  68. package/dist/esm/solana/lib/derive-accounts.d.ts +4 -0
  69. package/dist/esm/solana/lib/derive-accounts.js +11 -0
  70. package/dist/esm/solana/{utils.d.ts → lib/utils.d.ts} +1 -3
  71. package/dist/esm/solana/{utils.js → lib/utils.js} +28 -34
  72. package/dist/esm/solana/types.d.ts +72 -39
  73. package/dist/esm/solana/types.js +32 -4
  74. package/dist/esm/sui/StreamClient.js +1 -1
  75. package/dist/esm/sui/types.d.ts +14 -14
  76. package/dist/esm/sui/types.js +13 -13
  77. package/package.json +12 -10
  78. 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 { Types, GenericStreamClient, getScaledBigNumber, getNumberFromBigNumber } from "@streamflow/stream";
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
- Types.IChain.Ethereum,
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
- Types.IChain.Polygon,
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
- Types.IChain.BNB,
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, Types } from "@streamflow/stream";
106
+ import { GenericStreamClient } from "@streamflow/stream";
124
107
 
125
108
  const client =
126
109
  new GenericStreamClient<Types.IChain.Solana>({
127
- chain: Types.IChain.Solana, // Blockchain
110
+ chain: IChain.Solana, // Blockchain
128
111
  clusterUrl: "https://api.mainnet-beta.solana.com", // RPC cluster URL
129
- cluster: Types.ICluster.Mainnet, // (optional) (default: Mainnet)
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: getScaledBigNumber(100, 9), // depositing 100 tokens with 9 decimals mint.
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: getScaledBigNumber(5, 9), // Release rate: how many tokens are unlocked per each period.
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: null, // (optional) Partner's wallet address (string | null).
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] Wether Stream or Vesting should be paid with Solana native token or not
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: getScaledBgNumber(100, 9), // depositing 100 tokens with 9 decimals mint.
173
+ amount: getBN(100, 9), // depositing 100 tokens with 9 decimals mint.
191
174
  name: "January Payroll", // The stream name/subject.
192
- cliffAmount: getScaledBgNumber(10, 9), // amount released on cliff for this recipient
193
- amountPerPeriod: getScaledBgNumber(1, 9), //amount released every specified period epoch
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 createStreamParams: Types.ICreateMultipleStreamData = {
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: null, // (optional) Partner's wallet address (string | null).
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 `Types.ICreateResult` object (`createdMultiple` returns an Array) that has the following structure
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 | Types.TransactionPayload)[];
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: getScaledBgNumber(100, 9), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
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: Types.ITopUpData = {
285
- id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be topped up.
286
- amount: getScaledBgNumber(100, 9), // Specified amount to topup (increases deposited 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: Types.ITransferData = {
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: Types.ICancelData = {
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: Types.IUpdateData = {
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: getScaledBgNumber(10, 9), // [optional], allows to update release amount effective on next unlock
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: Types.IGetOneData = {
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); // bignumber amount unlocked at the tsInSeconds
427
- console.log(getNumberFromBigNumber(unlocked, 9));
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; // big number amount withdrawn already
439
- console.log(getNumberFromBigNumber(wihtdrawn, 9));
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: Types.IGetAllData = {
430
+ const data: IGetAllData = {
448
431
  address: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99",
449
- type: Types.StreamType.All,
450
- direction: Types.StreamDirection.All,
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 BigNumber amounts are denominated in their smallest units.**
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 `BigNumber(1_000_000_000)` is used.
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
- Use `getscaledBigNumber` and `getNumberFromBigNumber` utility functions for conversions between `BigNumber` and `Number` types.
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
- var bignumber_js_1 = require("bignumber.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 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", 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: (0, bignumber_js_1.BigNumber)(1000),
91
- name: "test name",
92
- cliffAmount: 1,
93
- amountPerPeriod: (0, bignumber_js_1.BigNumber)(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: 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
- 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
  });