@streamflow/stream 9.0.3 → 10.0.0-alpha.p313.3ce4d29

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 (42) hide show
  1. package/README.md +6 -62
  2. package/dist/cjs/index.cjs +421 -3786
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs/index.d.cts +3 -186
  5. package/dist/cjs/solana/index.cjs +376 -301
  6. package/dist/cjs/solana/index.cjs.map +1 -1
  7. package/dist/cjs/solana/index.d.cts +1134 -17
  8. package/dist/esm/index.d.ts +3 -186
  9. package/dist/esm/index.js +239 -3617
  10. package/dist/esm/index.js.map +1 -1
  11. package/dist/esm/solana/index.d.ts +1134 -17
  12. package/dist/esm/solana/index.js +257 -232
  13. package/dist/esm/solana/index.js.map +1 -1
  14. package/package.json +4 -43
  15. package/dist/cjs/BaseStreamClient-DOyJqO7R.d.cts +0 -551
  16. package/dist/cjs/aptos/index.cjs +0 -456
  17. package/dist/cjs/aptos/index.cjs.map +0 -1
  18. package/dist/cjs/aptos/index.d.cts +0 -14
  19. package/dist/cjs/evm/index.cjs +0 -1915
  20. package/dist/cjs/evm/index.cjs.map +0 -1
  21. package/dist/cjs/evm/index.d.cts +0 -13
  22. package/dist/cjs/index-BMZATAYa.d.cts +0 -213
  23. package/dist/cjs/index-BgGtpOPg.d.cts +0 -850
  24. package/dist/cjs/index-DYIamO0j.d.cts +0 -203
  25. package/dist/cjs/index-Y0HH2ugY.d.cts +0 -136
  26. package/dist/cjs/sui/index.cjs +0 -1021
  27. package/dist/cjs/sui/index.cjs.map +0 -1
  28. package/dist/cjs/sui/index.d.cts +0 -13
  29. package/dist/esm/BaseStreamClient-DOyJqO7R.d.ts +0 -551
  30. package/dist/esm/aptos/index.d.ts +0 -14
  31. package/dist/esm/aptos/index.js +0 -443
  32. package/dist/esm/aptos/index.js.map +0 -1
  33. package/dist/esm/evm/index.d.ts +0 -13
  34. package/dist/esm/evm/index.js +0 -1902
  35. package/dist/esm/evm/index.js.map +0 -1
  36. package/dist/esm/index-D54wSYym.d.ts +0 -203
  37. package/dist/esm/index-Dp5DXxr-.d.ts +0 -850
  38. package/dist/esm/index-DrzqsoIB.d.ts +0 -136
  39. package/dist/esm/index-elpYUBph.d.ts +0 -213
  40. package/dist/esm/sui/index.d.ts +0 -13
  41. package/dist/esm/sui/index.js +0 -1011
  42. package/dist/esm/sui/index.js.map +0 -1
@@ -1,1902 +0,0 @@
1
- import { ethers } from 'ethers';
2
- import BN4 from 'bn.js';
3
- import { toChecksumAddress } from 'ethereum-checksum-address';
4
- import { ICluster, IChain } from '@streamflow/common';
5
-
6
- var __defProp = Object.defineProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
-
12
- // common/BaseStreamClient.ts
13
- var BaseStreamClient = class {
14
- /**
15
- * Returns total fee percent, streamflow fees + partner fees
16
- * @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
17
- * @param chainSpecificParams additional parameters required by chain client
18
- * @returns fee as floating number, so if fee is 0.99%, it will return 0.99
19
- */
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- async getTotalFee(getFeesData, chainSpecificParams) {
22
- const fees = await this.getFees(getFeesData, chainSpecificParams);
23
- if (fees) {
24
- return fees.partnerFee + fees.streamflowFee;
25
- }
26
- return this.getDefaultStreamflowFee(chainSpecificParams);
27
- }
28
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
- extractErrorCode(err) {
30
- return null;
31
- }
32
- };
33
-
34
- // evm/constants.ts
35
- var constants_exports = {};
36
- __export(constants_exports, {
37
- BNB_PROGRAM_IDS: () => BNB_PROGRAM_IDS,
38
- ETHEREUM_PROGRAM_IDS: () => ETHEREUM_PROGRAM_IDS,
39
- EVM_ERROR_MAP: () => EVM_ERROR_MAP,
40
- EVM_ERROR_MATCH_REGEX: () => EVM_ERROR_MATCH_REGEX,
41
- POLYGON_PROGRAM_IDS: () => POLYGON_PROGRAM_IDS
42
- });
43
- var ETHEREUM_PROGRAM_IDS = {
44
- [ICluster.Mainnet]: "0x94d4646Bd307Bf91CB1893BC64d976BF9E60D9B2",
45
- [ICluster.Devnet]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
46
- [ICluster.Testnet]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
47
- [ICluster.Local]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d"
48
- };
49
- var BNB_PROGRAM_IDS = {
50
- [ICluster.Mainnet]: "0x94d4646Bd307Bf91CB1893BC64d976BF9E60D9B2",
51
- [ICluster.Devnet]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
52
- [ICluster.Testnet]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
53
- [ICluster.Local]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d"
54
- };
55
- var POLYGON_PROGRAM_IDS = {
56
- [ICluster.Mainnet]: "0x94d4646Bd307Bf91CB1893BC64d976BF9E60D9B2",
57
- [ICluster.Devnet]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
58
- [ICluster.Testnet]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
59
- [ICluster.Local]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d"
60
- };
61
- var EVM_ERROR_MATCH_REGEX = /execution reverted: ([A-Z_]+)/;
62
- var EVM_ERROR_MAP = {
63
- ECONTRACT_NOT_INIT: "ECONTRACT_NOT_INIT" /* ECONTRACT_NOT_INIT */,
64
- EBAD_AMOUNT: "EBAD_AMOUNT" /* EBAD_AMOUNT */,
65
- ENO_PERMISSIONS: "ENO_PERMISSIONS" /* ENO_PERMISSIONS */,
66
- EBADINPUT: "EBADINPUT" /* EBADINPUT */,
67
- ECLOSED: "ECLOSED" /* ECLOSED */,
68
- EBAD_INPUT_AMOUNT_PER_PERIOD: "EBAD_INPUT_AMOUNT_PER_PERIOD" /* EBAD_INPUT_AMOUNT_PER_PERIOD */,
69
- EBAD_INPUT_PAUSABLE: "EBAD_INPUT_PAUSABLE" /* EBAD_INPUT_PAUSABLE */,
70
- EBAD_INPUT_UPDATE_RATE: "EBAD_INPUT_UPDATE_RATE" /* EBAD_INPUT_UPDATE_RATE */,
71
- EBAD_INPUT_CLIFF_AMOUNT: "EBAD_INPUT_CLIFF_AMOUNT" /* EBAD_INPUT_CLIFF_AMOUNT */,
72
- EBAD_INPUT_PERIOD: "EBAD_INPUT_PERIOD" /* EBAD_INPUT_PERIOD */,
73
- EBAD_INPUT_START: "EBAD_INPUT_START" /* EBAD_INPUT_START */,
74
- EBAD_INSUFFICIENT_TOKEN_ALLOWANCE: "EBAD_INSUFFICIENT_TOKEN_ALLOWANCE" /* EBAD_INSUFFICIENT_TOKEN_ALLOWANCE */,
75
- EBAD_INSUFFICIENT_WITHDRAWAL_FEES: "EBAD_INSUFFICIENT_WITHDRAWAL_FEES" /* EBAD_INSUFFICIENT_WITHDRAWAL_FEES */
76
- };
77
-
78
- // evm/abi.ts
79
- var abi_default = [
80
- {
81
- anonymous: false,
82
- inputs: [
83
- {
84
- indexed: false,
85
- internalType: "address",
86
- name: "",
87
- type: "address"
88
- }
89
- ],
90
- name: "ContractCreated",
91
- type: "event"
92
- },
93
- {
94
- inputs: [
95
- {
96
- internalType: "address",
97
- name: "_stream_id",
98
- type: "address"
99
- }
100
- ],
101
- name: "cancel",
102
- outputs: [],
103
- stateMutability: "nonpayable",
104
- type: "function"
105
- },
106
- {
107
- inputs: [
108
- {
109
- internalType: "uint256",
110
- name: "_new_fees",
111
- type: "uint256"
112
- }
113
- ],
114
- name: "changeStreamflowFees",
115
- outputs: [],
116
- stateMutability: "nonpayable",
117
- type: "function"
118
- },
119
- {
120
- inputs: [
121
- {
122
- internalType: "address payable",
123
- name: "_new_treasury",
124
- type: "address"
125
- }
126
- ],
127
- name: "changeTreasury",
128
- outputs: [],
129
- stateMutability: "nonpayable",
130
- type: "function"
131
- },
132
- {
133
- inputs: [
134
- {
135
- internalType: "uint256",
136
- name: "_new_fee",
137
- type: "uint256"
138
- }
139
- ],
140
- name: "changeTxFee",
141
- outputs: [],
142
- stateMutability: "nonpayable",
143
- type: "function"
144
- },
145
- {
146
- inputs: [
147
- {
148
- internalType: "address payable",
149
- name: "_new_withdawor",
150
- type: "address"
151
- }
152
- ],
153
- name: "changeWithdrawor",
154
- outputs: [],
155
- stateMutability: "nonpayable",
156
- type: "function"
157
- },
158
- {
159
- inputs: [],
160
- name: "config",
161
- outputs: [
162
- {
163
- internalType: "address",
164
- name: "admin",
165
- type: "address"
166
- },
167
- {
168
- internalType: "uint256",
169
- name: "streamflow_fees",
170
- type: "uint256"
171
- },
172
- {
173
- internalType: "address payable",
174
- name: "treasury",
175
- type: "address"
176
- },
177
- {
178
- internalType: "address payable",
179
- name: "withdrawor",
180
- type: "address"
181
- },
182
- {
183
- internalType: "uint256",
184
- name: "tx_fee",
185
- type: "uint256"
186
- }
187
- ],
188
- stateMutability: "view",
189
- type: "function"
190
- },
191
- {
192
- inputs: [
193
- {
194
- internalType: "contract IERC20",
195
- name: "_token",
196
- type: "address"
197
- },
198
- {
199
- internalType: "uint256",
200
- name: "_amount",
201
- type: "uint256"
202
- },
203
- {
204
- internalType: "uint256",
205
- name: "_period",
206
- type: "uint256"
207
- },
208
- {
209
- internalType: "uint256",
210
- name: "_amount_per_period",
211
- type: "uint256"
212
- },
213
- {
214
- internalType: "uint256",
215
- name: "_start",
216
- type: "uint256"
217
- },
218
- {
219
- internalType: "uint256",
220
- name: "_cliff_amount",
221
- type: "uint256"
222
- },
223
- {
224
- components: [
225
- {
226
- internalType: "bool",
227
- name: "cancelable_by_sender",
228
- type: "bool"
229
- },
230
- {
231
- internalType: "bool",
232
- name: "cancelable_by_recipient",
233
- type: "bool"
234
- },
235
- {
236
- internalType: "bool",
237
- name: "transferable_by_sender",
238
- type: "bool"
239
- },
240
- {
241
- internalType: "bool",
242
- name: "transferable_by_recipient",
243
- type: "bool"
244
- },
245
- {
246
- internalType: "bool",
247
- name: "can_topup",
248
- type: "bool"
249
- },
250
- {
251
- internalType: "bool",
252
- name: "pausable",
253
- type: "bool"
254
- },
255
- {
256
- internalType: "bool",
257
- name: "can_update_rate",
258
- type: "bool"
259
- },
260
- {
261
- internalType: "bool",
262
- name: "automatic_withdrawal",
263
- type: "bool"
264
- },
265
- {
266
- internalType: "uint256",
267
- name: "withdrawal_frequency",
268
- type: "uint256"
269
- },
270
- {
271
- internalType: "string",
272
- name: "contract_name",
273
- type: "string"
274
- }
275
- ],
276
- internalType: "struct ContractMeta",
277
- name: "_meta",
278
- type: "tuple"
279
- },
280
- {
281
- internalType: "address",
282
- name: "_recipient",
283
- type: "address"
284
- },
285
- {
286
- internalType: "address",
287
- name: "_partner",
288
- type: "address"
289
- }
290
- ],
291
- name: "create",
292
- outputs: [],
293
- stateMutability: "payable",
294
- type: "function"
295
- },
296
- {
297
- inputs: [
298
- {
299
- internalType: "address",
300
- name: "_address",
301
- type: "address"
302
- }
303
- ],
304
- name: "feesRemove",
305
- outputs: [],
306
- stateMutability: "nonpayable",
307
- type: "function"
308
- },
309
- {
310
- inputs: [
311
- {
312
- internalType: "address",
313
- name: "_address",
314
- type: "address"
315
- },
316
- {
317
- internalType: "uint256",
318
- name: "streamflow_fee",
319
- type: "uint256"
320
- },
321
- {
322
- internalType: "uint256",
323
- name: "partner_fee",
324
- type: "uint256"
325
- }
326
- ],
327
- name: "feesWrite",
328
- outputs: [],
329
- stateMutability: "nonpayable",
330
- type: "function"
331
- },
332
- {
333
- inputs: [],
334
- name: "getAdmin",
335
- outputs: [
336
- {
337
- internalType: "address",
338
- name: "",
339
- type: "address"
340
- }
341
- ],
342
- stateMutability: "view",
343
- type: "function"
344
- },
345
- {
346
- inputs: [],
347
- name: "getAll",
348
- outputs: [
349
- {
350
- internalType: "address[]",
351
- name: "",
352
- type: "address[]"
353
- },
354
- {
355
- components: [
356
- {
357
- internalType: "contract IERC20",
358
- name: "token",
359
- type: "address"
360
- },
361
- {
362
- components: [
363
- {
364
- internalType: "bool",
365
- name: "cancelable_by_sender",
366
- type: "bool"
367
- },
368
- {
369
- internalType: "bool",
370
- name: "cancelable_by_recipient",
371
- type: "bool"
372
- },
373
- {
374
- internalType: "bool",
375
- name: "transferable_by_sender",
376
- type: "bool"
377
- },
378
- {
379
- internalType: "bool",
380
- name: "transferable_by_recipient",
381
- type: "bool"
382
- },
383
- {
384
- internalType: "bool",
385
- name: "can_topup",
386
- type: "bool"
387
- },
388
- {
389
- internalType: "bool",
390
- name: "pausable",
391
- type: "bool"
392
- },
393
- {
394
- internalType: "bool",
395
- name: "can_update_rate",
396
- type: "bool"
397
- },
398
- {
399
- internalType: "bool",
400
- name: "automatic_withdrawal",
401
- type: "bool"
402
- },
403
- {
404
- internalType: "uint256",
405
- name: "withdrawal_frequency",
406
- type: "uint256"
407
- },
408
- {
409
- internalType: "string",
410
- name: "contract_name",
411
- type: "string"
412
- }
413
- ],
414
- internalType: "struct ContractMeta",
415
- name: "meta",
416
- type: "tuple"
417
- },
418
- {
419
- internalType: "uint256",
420
- name: "amount",
421
- type: "uint256"
422
- },
423
- {
424
- internalType: "uint256",
425
- name: "period",
426
- type: "uint256"
427
- },
428
- {
429
- internalType: "uint256",
430
- name: "amount_per_period",
431
- type: "uint256"
432
- },
433
- {
434
- internalType: "uint256",
435
- name: "start",
436
- type: "uint256"
437
- },
438
- {
439
- internalType: "uint256",
440
- name: "end",
441
- type: "uint256"
442
- },
443
- {
444
- internalType: "uint256",
445
- name: "cliff_amount",
446
- type: "uint256"
447
- },
448
- {
449
- internalType: "uint256",
450
- name: "withdrawn",
451
- type: "uint256"
452
- },
453
- {
454
- internalType: "uint256",
455
- name: "last_withdrawn_at",
456
- type: "uint256"
457
- },
458
- {
459
- internalType: "uint256",
460
- name: "created",
461
- type: "uint256"
462
- },
463
- {
464
- internalType: "uint256",
465
- name: "canceled_at",
466
- type: "uint256"
467
- },
468
- {
469
- internalType: "address",
470
- name: "recipient",
471
- type: "address"
472
- },
473
- {
474
- internalType: "address",
475
- name: "sender",
476
- type: "address"
477
- },
478
- {
479
- internalType: "address",
480
- name: "partner",
481
- type: "address"
482
- },
483
- {
484
- components: [
485
- {
486
- internalType: "uint256",
487
- name: "streamflow_fee_percentage",
488
- type: "uint256"
489
- },
490
- {
491
- internalType: "uint256",
492
- name: "streamflow_fee",
493
- type: "uint256"
494
- },
495
- {
496
- internalType: "uint256",
497
- name: "streamflow_fee_withdrawn",
498
- type: "uint256"
499
- },
500
- {
501
- internalType: "uint256",
502
- name: "partner_fee_percentage",
503
- type: "uint256"
504
- },
505
- {
506
- internalType: "uint256",
507
- name: "partner_fee",
508
- type: "uint256"
509
- },
510
- {
511
- internalType: "uint256",
512
- name: "partner_fee_withdrawn",
513
- type: "uint256"
514
- },
515
- {
516
- internalType: "uint256",
517
- name: "tx_fee",
518
- type: "uint256"
519
- }
520
- ],
521
- internalType: "struct FeesData",
522
- name: "fees",
523
- type: "tuple"
524
- },
525
- {
526
- internalType: "bool",
527
- name: "closed",
528
- type: "bool"
529
- },
530
- {
531
- internalType: "uint256",
532
- name: "current_pause_start",
533
- type: "uint256"
534
- },
535
- {
536
- internalType: "uint256",
537
- name: "pause_cumulative",
538
- type: "uint256"
539
- },
540
- {
541
- internalType: "uint256",
542
- name: "last_rate_change_time",
543
- type: "uint256"
544
- },
545
- {
546
- internalType: "uint256",
547
- name: "funds_unlocked_at_last_rate_change",
548
- type: "uint256"
549
- }
550
- ],
551
- internalType: "struct Contract[]",
552
- name: "",
553
- type: "tuple[]"
554
- }
555
- ],
556
- stateMutability: "view",
557
- type: "function"
558
- },
559
- {
560
- inputs: [
561
- {
562
- internalType: "address",
563
- name: "_id",
564
- type: "address"
565
- }
566
- ],
567
- name: "getById",
568
- outputs: [
569
- {
570
- components: [
571
- {
572
- internalType: "contract IERC20",
573
- name: "token",
574
- type: "address"
575
- },
576
- {
577
- components: [
578
- {
579
- internalType: "bool",
580
- name: "cancelable_by_sender",
581
- type: "bool"
582
- },
583
- {
584
- internalType: "bool",
585
- name: "cancelable_by_recipient",
586
- type: "bool"
587
- },
588
- {
589
- internalType: "bool",
590
- name: "transferable_by_sender",
591
- type: "bool"
592
- },
593
- {
594
- internalType: "bool",
595
- name: "transferable_by_recipient",
596
- type: "bool"
597
- },
598
- {
599
- internalType: "bool",
600
- name: "can_topup",
601
- type: "bool"
602
- },
603
- {
604
- internalType: "bool",
605
- name: "pausable",
606
- type: "bool"
607
- },
608
- {
609
- internalType: "bool",
610
- name: "can_update_rate",
611
- type: "bool"
612
- },
613
- {
614
- internalType: "bool",
615
- name: "automatic_withdrawal",
616
- type: "bool"
617
- },
618
- {
619
- internalType: "uint256",
620
- name: "withdrawal_frequency",
621
- type: "uint256"
622
- },
623
- {
624
- internalType: "string",
625
- name: "contract_name",
626
- type: "string"
627
- }
628
- ],
629
- internalType: "struct ContractMeta",
630
- name: "meta",
631
- type: "tuple"
632
- },
633
- {
634
- internalType: "uint256",
635
- name: "amount",
636
- type: "uint256"
637
- },
638
- {
639
- internalType: "uint256",
640
- name: "period",
641
- type: "uint256"
642
- },
643
- {
644
- internalType: "uint256",
645
- name: "amount_per_period",
646
- type: "uint256"
647
- },
648
- {
649
- internalType: "uint256",
650
- name: "start",
651
- type: "uint256"
652
- },
653
- {
654
- internalType: "uint256",
655
- name: "end",
656
- type: "uint256"
657
- },
658
- {
659
- internalType: "uint256",
660
- name: "cliff_amount",
661
- type: "uint256"
662
- },
663
- {
664
- internalType: "uint256",
665
- name: "withdrawn",
666
- type: "uint256"
667
- },
668
- {
669
- internalType: "uint256",
670
- name: "last_withdrawn_at",
671
- type: "uint256"
672
- },
673
- {
674
- internalType: "uint256",
675
- name: "created",
676
- type: "uint256"
677
- },
678
- {
679
- internalType: "uint256",
680
- name: "canceled_at",
681
- type: "uint256"
682
- },
683
- {
684
- internalType: "address",
685
- name: "recipient",
686
- type: "address"
687
- },
688
- {
689
- internalType: "address",
690
- name: "sender",
691
- type: "address"
692
- },
693
- {
694
- internalType: "address",
695
- name: "partner",
696
- type: "address"
697
- },
698
- {
699
- components: [
700
- {
701
- internalType: "uint256",
702
- name: "streamflow_fee_percentage",
703
- type: "uint256"
704
- },
705
- {
706
- internalType: "uint256",
707
- name: "streamflow_fee",
708
- type: "uint256"
709
- },
710
- {
711
- internalType: "uint256",
712
- name: "streamflow_fee_withdrawn",
713
- type: "uint256"
714
- },
715
- {
716
- internalType: "uint256",
717
- name: "partner_fee_percentage",
718
- type: "uint256"
719
- },
720
- {
721
- internalType: "uint256",
722
- name: "partner_fee",
723
- type: "uint256"
724
- },
725
- {
726
- internalType: "uint256",
727
- name: "partner_fee_withdrawn",
728
- type: "uint256"
729
- },
730
- {
731
- internalType: "uint256",
732
- name: "tx_fee",
733
- type: "uint256"
734
- }
735
- ],
736
- internalType: "struct FeesData",
737
- name: "fees",
738
- type: "tuple"
739
- },
740
- {
741
- internalType: "bool",
742
- name: "closed",
743
- type: "bool"
744
- },
745
- {
746
- internalType: "uint256",
747
- name: "current_pause_start",
748
- type: "uint256"
749
- },
750
- {
751
- internalType: "uint256",
752
- name: "pause_cumulative",
753
- type: "uint256"
754
- },
755
- {
756
- internalType: "uint256",
757
- name: "last_rate_change_time",
758
- type: "uint256"
759
- },
760
- {
761
- internalType: "uint256",
762
- name: "funds_unlocked_at_last_rate_change",
763
- type: "uint256"
764
- }
765
- ],
766
- internalType: "struct Contract",
767
- name: "",
768
- type: "tuple"
769
- }
770
- ],
771
- stateMutability: "view",
772
- type: "function"
773
- },
774
- {
775
- inputs: [
776
- {
777
- internalType: "address",
778
- name: "_recipient",
779
- type: "address"
780
- }
781
- ],
782
- name: "getByRecipient",
783
- outputs: [
784
- {
785
- internalType: "address[]",
786
- name: "",
787
- type: "address[]"
788
- }
789
- ],
790
- stateMutability: "view",
791
- type: "function"
792
- },
793
- {
794
- inputs: [
795
- {
796
- internalType: "address",
797
- name: "_sender",
798
- type: "address"
799
- }
800
- ],
801
- name: "getBySender",
802
- outputs: [
803
- {
804
- internalType: "address[]",
805
- name: "",
806
- type: "address[]"
807
- }
808
- ],
809
- stateMutability: "view",
810
- type: "function"
811
- },
812
- {
813
- inputs: [
814
- {
815
- internalType: "address",
816
- name: "_address",
817
- type: "address"
818
- }
819
- ],
820
- name: "getFees",
821
- outputs: [
822
- {
823
- components: [
824
- {
825
- internalType: "bool",
826
- name: "exists",
827
- type: "bool"
828
- },
829
- {
830
- internalType: "uint256",
831
- name: "streamflow_fee",
832
- type: "uint256"
833
- },
834
- {
835
- internalType: "uint256",
836
- name: "partner_fee",
837
- type: "uint256"
838
- }
839
- ],
840
- internalType: "struct StreamflowFeeManager.FeeValue",
841
- name: "",
842
- type: "tuple"
843
- }
844
- ],
845
- stateMutability: "view",
846
- type: "function"
847
- },
848
- {
849
- inputs: [
850
- {
851
- internalType: "address[]",
852
- name: "_ids",
853
- type: "address[]"
854
- }
855
- ],
856
- name: "getMultiple",
857
- outputs: [
858
- {
859
- components: [
860
- {
861
- internalType: "contract IERC20",
862
- name: "token",
863
- type: "address"
864
- },
865
- {
866
- components: [
867
- {
868
- internalType: "bool",
869
- name: "cancelable_by_sender",
870
- type: "bool"
871
- },
872
- {
873
- internalType: "bool",
874
- name: "cancelable_by_recipient",
875
- type: "bool"
876
- },
877
- {
878
- internalType: "bool",
879
- name: "transferable_by_sender",
880
- type: "bool"
881
- },
882
- {
883
- internalType: "bool",
884
- name: "transferable_by_recipient",
885
- type: "bool"
886
- },
887
- {
888
- internalType: "bool",
889
- name: "can_topup",
890
- type: "bool"
891
- },
892
- {
893
- internalType: "bool",
894
- name: "pausable",
895
- type: "bool"
896
- },
897
- {
898
- internalType: "bool",
899
- name: "can_update_rate",
900
- type: "bool"
901
- },
902
- {
903
- internalType: "bool",
904
- name: "automatic_withdrawal",
905
- type: "bool"
906
- },
907
- {
908
- internalType: "uint256",
909
- name: "withdrawal_frequency",
910
- type: "uint256"
911
- },
912
- {
913
- internalType: "string",
914
- name: "contract_name",
915
- type: "string"
916
- }
917
- ],
918
- internalType: "struct ContractMeta",
919
- name: "meta",
920
- type: "tuple"
921
- },
922
- {
923
- internalType: "uint256",
924
- name: "amount",
925
- type: "uint256"
926
- },
927
- {
928
- internalType: "uint256",
929
- name: "period",
930
- type: "uint256"
931
- },
932
- {
933
- internalType: "uint256",
934
- name: "amount_per_period",
935
- type: "uint256"
936
- },
937
- {
938
- internalType: "uint256",
939
- name: "start",
940
- type: "uint256"
941
- },
942
- {
943
- internalType: "uint256",
944
- name: "end",
945
- type: "uint256"
946
- },
947
- {
948
- internalType: "uint256",
949
- name: "cliff_amount",
950
- type: "uint256"
951
- },
952
- {
953
- internalType: "uint256",
954
- name: "withdrawn",
955
- type: "uint256"
956
- },
957
- {
958
- internalType: "uint256",
959
- name: "last_withdrawn_at",
960
- type: "uint256"
961
- },
962
- {
963
- internalType: "uint256",
964
- name: "created",
965
- type: "uint256"
966
- },
967
- {
968
- internalType: "uint256",
969
- name: "canceled_at",
970
- type: "uint256"
971
- },
972
- {
973
- internalType: "address",
974
- name: "recipient",
975
- type: "address"
976
- },
977
- {
978
- internalType: "address",
979
- name: "sender",
980
- type: "address"
981
- },
982
- {
983
- internalType: "address",
984
- name: "partner",
985
- type: "address"
986
- },
987
- {
988
- components: [
989
- {
990
- internalType: "uint256",
991
- name: "streamflow_fee_percentage",
992
- type: "uint256"
993
- },
994
- {
995
- internalType: "uint256",
996
- name: "streamflow_fee",
997
- type: "uint256"
998
- },
999
- {
1000
- internalType: "uint256",
1001
- name: "streamflow_fee_withdrawn",
1002
- type: "uint256"
1003
- },
1004
- {
1005
- internalType: "uint256",
1006
- name: "partner_fee_percentage",
1007
- type: "uint256"
1008
- },
1009
- {
1010
- internalType: "uint256",
1011
- name: "partner_fee",
1012
- type: "uint256"
1013
- },
1014
- {
1015
- internalType: "uint256",
1016
- name: "partner_fee_withdrawn",
1017
- type: "uint256"
1018
- },
1019
- {
1020
- internalType: "uint256",
1021
- name: "tx_fee",
1022
- type: "uint256"
1023
- }
1024
- ],
1025
- internalType: "struct FeesData",
1026
- name: "fees",
1027
- type: "tuple"
1028
- },
1029
- {
1030
- internalType: "bool",
1031
- name: "closed",
1032
- type: "bool"
1033
- },
1034
- {
1035
- internalType: "uint256",
1036
- name: "current_pause_start",
1037
- type: "uint256"
1038
- },
1039
- {
1040
- internalType: "uint256",
1041
- name: "pause_cumulative",
1042
- type: "uint256"
1043
- },
1044
- {
1045
- internalType: "uint256",
1046
- name: "last_rate_change_time",
1047
- type: "uint256"
1048
- },
1049
- {
1050
- internalType: "uint256",
1051
- name: "funds_unlocked_at_last_rate_change",
1052
- type: "uint256"
1053
- }
1054
- ],
1055
- internalType: "struct Contract[]",
1056
- name: "",
1057
- type: "tuple[]"
1058
- }
1059
- ],
1060
- stateMutability: "view",
1061
- type: "function"
1062
- },
1063
- {
1064
- inputs: [
1065
- {
1066
- internalType: "address",
1067
- name: "_address",
1068
- type: "address"
1069
- }
1070
- ],
1071
- name: "getStreamflowFee",
1072
- outputs: [
1073
- {
1074
- internalType: "uint256",
1075
- name: "",
1076
- type: "uint256"
1077
- }
1078
- ],
1079
- stateMutability: "view",
1080
- type: "function"
1081
- },
1082
- {
1083
- inputs: [],
1084
- name: "getStreamflowFees",
1085
- outputs: [
1086
- {
1087
- internalType: "uint256",
1088
- name: "",
1089
- type: "uint256"
1090
- }
1091
- ],
1092
- stateMutability: "view",
1093
- type: "function"
1094
- },
1095
- {
1096
- inputs: [
1097
- {
1098
- internalType: "address",
1099
- name: "_stream_id",
1100
- type: "address"
1101
- },
1102
- {
1103
- internalType: "uint256",
1104
- name: "_amount",
1105
- type: "uint256"
1106
- }
1107
- ],
1108
- name: "getTopUpWithdrawalFees",
1109
- outputs: [
1110
- {
1111
- components: [
1112
- {
1113
- internalType: "uint256",
1114
- name: "value",
1115
- type: "uint256"
1116
- },
1117
- {
1118
- internalType: "uint256",
1119
- name: "tx_fee",
1120
- type: "uint256"
1121
- }
1122
- ],
1123
- internalType: "struct WithdrawalFeesData",
1124
- name: "",
1125
- type: "tuple"
1126
- }
1127
- ],
1128
- stateMutability: "view",
1129
- type: "function"
1130
- },
1131
- {
1132
- inputs: [],
1133
- name: "getTreasuryAddress",
1134
- outputs: [
1135
- {
1136
- internalType: "address payable",
1137
- name: "",
1138
- type: "address"
1139
- }
1140
- ],
1141
- stateMutability: "view",
1142
- type: "function"
1143
- },
1144
- {
1145
- inputs: [],
1146
- name: "getTxFee",
1147
- outputs: [
1148
- {
1149
- internalType: "uint256",
1150
- name: "",
1151
- type: "uint256"
1152
- }
1153
- ],
1154
- stateMutability: "view",
1155
- type: "function"
1156
- },
1157
- {
1158
- inputs: [
1159
- {
1160
- internalType: "uint256",
1161
- name: "_amount",
1162
- type: "uint256"
1163
- },
1164
- {
1165
- internalType: "uint256",
1166
- name: "_period",
1167
- type: "uint256"
1168
- },
1169
- {
1170
- internalType: "uint256",
1171
- name: "_amount_per_period",
1172
- type: "uint256"
1173
- },
1174
- {
1175
- internalType: "uint256",
1176
- name: "_start",
1177
- type: "uint256"
1178
- },
1179
- {
1180
- internalType: "uint256",
1181
- name: "_cliff_amount",
1182
- type: "uint256"
1183
- },
1184
- {
1185
- internalType: "bool",
1186
- name: "_automatic_withdrawal",
1187
- type: "bool"
1188
- },
1189
- {
1190
- internalType: "uint256",
1191
- name: "_withdrawal_frequency",
1192
- type: "uint256"
1193
- }
1194
- ],
1195
- name: "getWithdrawalFees",
1196
- outputs: [
1197
- {
1198
- components: [
1199
- {
1200
- internalType: "uint256",
1201
- name: "value",
1202
- type: "uint256"
1203
- },
1204
- {
1205
- internalType: "uint256",
1206
- name: "tx_fee",
1207
- type: "uint256"
1208
- }
1209
- ],
1210
- internalType: "struct WithdrawalFeesData",
1211
- name: "",
1212
- type: "tuple"
1213
- }
1214
- ],
1215
- stateMutability: "view",
1216
- type: "function"
1217
- },
1218
- {
1219
- inputs: [],
1220
- name: "getWithdraworAddress",
1221
- outputs: [
1222
- {
1223
- internalType: "address payable",
1224
- name: "",
1225
- type: "address"
1226
- }
1227
- ],
1228
- stateMutability: "view",
1229
- type: "function"
1230
- },
1231
- {
1232
- inputs: [],
1233
- name: "initialize",
1234
- outputs: [],
1235
- stateMutability: "nonpayable",
1236
- type: "function"
1237
- },
1238
- {
1239
- inputs: [
1240
- {
1241
- internalType: "address",
1242
- name: "_stream_id",
1243
- type: "address"
1244
- },
1245
- {
1246
- internalType: "uint256",
1247
- name: "_amount",
1248
- type: "uint256"
1249
- }
1250
- ],
1251
- name: "topUp",
1252
- outputs: [],
1253
- stateMutability: "payable",
1254
- type: "function"
1255
- },
1256
- {
1257
- inputs: [
1258
- {
1259
- internalType: "address",
1260
- name: "_stream_id",
1261
- type: "address"
1262
- },
1263
- {
1264
- internalType: "address",
1265
- name: "new_recipient",
1266
- type: "address"
1267
- }
1268
- ],
1269
- name: "transfer",
1270
- outputs: [],
1271
- stateMutability: "nonpayable",
1272
- type: "function"
1273
- },
1274
- {
1275
- inputs: [
1276
- {
1277
- internalType: "address",
1278
- name: "_new_admin",
1279
- type: "address"
1280
- }
1281
- ],
1282
- name: "transferAdmin",
1283
- outputs: [],
1284
- stateMutability: "nonpayable",
1285
- type: "function"
1286
- },
1287
- {
1288
- inputs: [
1289
- {
1290
- internalType: "address",
1291
- name: "_stream_id",
1292
- type: "address"
1293
- },
1294
- {
1295
- internalType: "bool[]",
1296
- name: "_automatic_withdrawal",
1297
- type: "bool[]"
1298
- },
1299
- {
1300
- internalType: "uint256[]",
1301
- name: "_withdrawal_frequency",
1302
- type: "uint256[]"
1303
- },
1304
- {
1305
- internalType: "uint256[]",
1306
- name: "_amount_per_period",
1307
- type: "uint256[]"
1308
- }
1309
- ],
1310
- name: "update",
1311
- outputs: [],
1312
- stateMutability: "payable",
1313
- type: "function"
1314
- },
1315
- {
1316
- inputs: [
1317
- {
1318
- internalType: "address",
1319
- name: "_stream_id",
1320
- type: "address"
1321
- },
1322
- {
1323
- internalType: "uint256",
1324
- name: "_amount",
1325
- type: "uint256"
1326
- }
1327
- ],
1328
- name: "withdraw",
1329
- outputs: [],
1330
- stateMutability: "nonpayable",
1331
- type: "function"
1332
- }
1333
- ];
1334
-
1335
- // evm/ercAbi.ts
1336
- var ercAbi_default = [
1337
- {
1338
- constant: true,
1339
- inputs: [],
1340
- name: "name",
1341
- outputs: [
1342
- {
1343
- name: "",
1344
- type: "string"
1345
- }
1346
- ],
1347
- payable: false,
1348
- stateMutability: "view",
1349
- type: "function"
1350
- },
1351
- {
1352
- constant: false,
1353
- inputs: [
1354
- {
1355
- name: "_spender",
1356
- type: "address"
1357
- },
1358
- {
1359
- name: "_value",
1360
- type: "uint256"
1361
- }
1362
- ],
1363
- name: "approve",
1364
- outputs: [
1365
- {
1366
- name: "",
1367
- type: "bool"
1368
- }
1369
- ],
1370
- payable: false,
1371
- stateMutability: "nonpayable",
1372
- type: "function"
1373
- },
1374
- {
1375
- constant: true,
1376
- inputs: [],
1377
- name: "totalSupply",
1378
- outputs: [
1379
- {
1380
- name: "",
1381
- type: "uint256"
1382
- }
1383
- ],
1384
- payable: false,
1385
- stateMutability: "view",
1386
- type: "function"
1387
- },
1388
- {
1389
- constant: false,
1390
- inputs: [
1391
- {
1392
- name: "_from",
1393
- type: "address"
1394
- },
1395
- {
1396
- name: "_to",
1397
- type: "address"
1398
- },
1399
- {
1400
- name: "_value",
1401
- type: "uint256"
1402
- }
1403
- ],
1404
- name: "transferFrom",
1405
- outputs: [
1406
- {
1407
- name: "",
1408
- type: "bool"
1409
- }
1410
- ],
1411
- payable: false,
1412
- stateMutability: "nonpayable",
1413
- type: "function"
1414
- },
1415
- {
1416
- constant: true,
1417
- inputs: [],
1418
- name: "decimals",
1419
- outputs: [
1420
- {
1421
- name: "",
1422
- type: "uint8"
1423
- }
1424
- ],
1425
- payable: false,
1426
- stateMutability: "view",
1427
- type: "function"
1428
- },
1429
- {
1430
- constant: true,
1431
- inputs: [
1432
- {
1433
- name: "_owner",
1434
- type: "address"
1435
- }
1436
- ],
1437
- name: "balanceOf",
1438
- outputs: [
1439
- {
1440
- name: "balance",
1441
- type: "uint256"
1442
- }
1443
- ],
1444
- payable: false,
1445
- stateMutability: "view",
1446
- type: "function"
1447
- },
1448
- {
1449
- constant: true,
1450
- inputs: [],
1451
- name: "symbol",
1452
- outputs: [
1453
- {
1454
- name: "",
1455
- type: "string"
1456
- }
1457
- ],
1458
- payable: false,
1459
- stateMutability: "view",
1460
- type: "function"
1461
- },
1462
- {
1463
- constant: false,
1464
- inputs: [
1465
- {
1466
- name: "_to",
1467
- type: "address"
1468
- },
1469
- {
1470
- name: "_value",
1471
- type: "uint256"
1472
- }
1473
- ],
1474
- name: "transfer",
1475
- outputs: [
1476
- {
1477
- name: "",
1478
- type: "bool"
1479
- }
1480
- ],
1481
- payable: false,
1482
- stateMutability: "nonpayable",
1483
- type: "function"
1484
- },
1485
- {
1486
- constant: true,
1487
- inputs: [
1488
- {
1489
- name: "_owner",
1490
- type: "address"
1491
- },
1492
- {
1493
- name: "_spender",
1494
- type: "address"
1495
- }
1496
- ],
1497
- name: "allowance",
1498
- outputs: [
1499
- {
1500
- name: "",
1501
- type: "uint256"
1502
- }
1503
- ],
1504
- payable: false,
1505
- stateMutability: "view",
1506
- type: "function"
1507
- },
1508
- {
1509
- payable: true,
1510
- stateMutability: "payable",
1511
- type: "fallback"
1512
- },
1513
- {
1514
- anonymous: false,
1515
- inputs: [
1516
- {
1517
- indexed: true,
1518
- name: "owner",
1519
- type: "address"
1520
- },
1521
- {
1522
- indexed: true,
1523
- name: "spender",
1524
- type: "address"
1525
- },
1526
- {
1527
- indexed: false,
1528
- name: "value",
1529
- type: "uint256"
1530
- }
1531
- ],
1532
- name: "Approval",
1533
- type: "event"
1534
- },
1535
- {
1536
- anonymous: false,
1537
- inputs: [
1538
- {
1539
- indexed: true,
1540
- name: "from",
1541
- type: "address"
1542
- },
1543
- {
1544
- indexed: true,
1545
- name: "to",
1546
- type: "address"
1547
- },
1548
- {
1549
- indexed: false,
1550
- name: "value",
1551
- type: "uint256"
1552
- }
1553
- ],
1554
- name: "Transfer",
1555
- type: "event"
1556
- }
1557
- ];
1558
- var BASE_FEE = 1009900;
1559
- var WITHDRAW_AVAILABLE_AMOUNT = new BN4("18446744073709551615");
1560
- var calculateUnlockedAmount = ({
1561
- depositedAmount,
1562
- cliff,
1563
- cliffAmount,
1564
- end,
1565
- currentTimestamp,
1566
- lastRateChangeTime,
1567
- period,
1568
- amountPerPeriod,
1569
- fundsUnlockedAtLastRateChange
1570
- }) => {
1571
- const deposited = depositedAmount;
1572
- if (currentTimestamp < cliff) return new BN4(0);
1573
- if (currentTimestamp > end) return deposited;
1574
- const savedUnlockedFunds = lastRateChangeTime === 0 ? cliffAmount : fundsUnlockedAtLastRateChange;
1575
- const savedUnlockedFundsTime = lastRateChangeTime === 0 ? cliff : lastRateChangeTime;
1576
- const streamed = new BN4(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period)).mul(amountPerPeriod).add(savedUnlockedFunds);
1577
- return streamed.lt(deposited) ? streamed : deposited;
1578
- };
1579
- var isCliffCloseToDepositedAmount = (streamData) => {
1580
- return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new BN4(1)));
1581
- };
1582
- var isVesting = (streamData) => {
1583
- return !streamData.canTopup && !isCliffCloseToDepositedAmount(streamData) && !isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage);
1584
- };
1585
- var isDynamicLock = (minPrice, maxPrice, minPercentage, maxPercentage) => {
1586
- return !!minPrice && !!maxPrice && minPrice > 0 && maxPrice - minPrice <= 1 && minPercentage === 0 && maxPercentage === 100;
1587
- };
1588
- var isTokenLock = (streamData) => {
1589
- return !streamData.canTopup && !streamData.automaticWithdrawal && !streamData.cancelableBySender && !streamData.cancelableByRecipient && !streamData.transferableBySender && (isCliffCloseToDepositedAmount(streamData) || isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage));
1590
- };
1591
- var buildStreamType = (streamData) => {
1592
- if (isVesting(streamData)) {
1593
- return "vesting" /* Vesting */;
1594
- }
1595
- if (isTokenLock(streamData)) {
1596
- return "lock" /* Lock */;
1597
- }
1598
- return "payment" /* Payment */;
1599
- };
1600
- new BN4(10 ** 6);
1601
- var getNumberFromBN = (value, decimals) => value.gt(new BN4(2 ** 53 - 1)) ? value.div(new BN4(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;
1602
-
1603
- // evm/types.ts
1604
- var EvmContract = class {
1605
- constructor(stream) {
1606
- this.magic = 0;
1607
- this.version = 0;
1608
- this.createdAt = stream.created.toNumber();
1609
- this.withdrawnAmount = new BN4(stream.withdrawn.toString());
1610
- this.canceledAt = stream.canceled_at.toNumber();
1611
- this.end = stream.end.toNumber();
1612
- this.lastWithdrawnAt = stream.last_withdrawn_at.toNumber();
1613
- this.sender = stream.sender;
1614
- this.senderTokens = stream.sender;
1615
- this.recipient = stream.recipient;
1616
- this.recipientTokens = stream.recipient;
1617
- this.mint = stream.token.toLowerCase();
1618
- this.escrowTokens = "";
1619
- this.streamflowTreasury = "";
1620
- this.streamflowTreasuryTokens = "";
1621
- this.streamflowFeeTotal = new BN4(stream.fees.streamflow_fee.toString());
1622
- this.streamflowFeeWithdrawn = new BN4(stream.fees.streamflow_fee_withdrawn.toString());
1623
- this.streamflowFeePercent = stream.fees.streamflow_fee_percentage.toNumber() / 1e4;
1624
- this.partnerFeeTotal = new BN4(0);
1625
- this.partnerFeeWithdrawn = new BN4(0);
1626
- this.partnerFeePercent = 0;
1627
- this.partner = "";
1628
- this.partnerTokens = "";
1629
- this.start = stream.start.toNumber();
1630
- this.depositedAmount = new BN4(stream.amount.toString());
1631
- this.period = stream.period.toNumber();
1632
- this.amountPerPeriod = new BN4(stream.amount_per_period.toString());
1633
- this.cliff = stream.start.toNumber();
1634
- this.cliffAmount = new BN4(stream.cliff_amount.toString());
1635
- this.cancelableBySender = stream.meta.cancelable_by_sender;
1636
- this.cancelableByRecipient = stream.meta.cancelable_by_recipient;
1637
- this.automaticWithdrawal = stream.meta.automatic_withdrawal;
1638
- this.transferableBySender = stream.meta.transferable_by_sender;
1639
- this.transferableByRecipient = stream.meta.transferable_by_recipient;
1640
- this.canTopup = stream.meta.can_topup;
1641
- this.name = stream.meta.contract_name;
1642
- this.withdrawalFrequency = stream.meta.withdrawal_frequency.toNumber();
1643
- this.closed = stream.closed;
1644
- this.currentPauseStart = stream.current_pause_start.toNumber();
1645
- this.pauseCumulative = new BN4(stream.pause_cumulative.toString());
1646
- this.lastRateChangeTime = stream.last_rate_change_time.toNumber();
1647
- this.fundsUnlockedAtLastRateChange = new BN4(stream.funds_unlocked_at_last_rate_change.toString());
1648
- this.type = buildStreamType(this);
1649
- }
1650
- unlocked(currentTimestamp) {
1651
- return calculateUnlockedAmount({
1652
- ...this,
1653
- currentTimestamp
1654
- });
1655
- }
1656
- remaining(decimals) {
1657
- return getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
1658
- }
1659
- };
1660
-
1661
- // evm/utils.ts
1662
- function extractEvmErrorCode(errorText) {
1663
- const match = EVM_ERROR_MATCH_REGEX.exec(errorText);
1664
- if (!match) {
1665
- return null;
1666
- }
1667
- return match[1];
1668
- }
1669
-
1670
- // evm/StreamClient.ts
1671
- var EvmStreamClient = class extends BaseStreamClient {
1672
- constructor(clusterUrl, chain, signer, cluster = ICluster.Mainnet, programId) {
1673
- super();
1674
- if (chain !== IChain.Ethereum && chain !== IChain.BNB && chain !== IChain.Polygon) {
1675
- throw new Error("Wrong chain. Supported chains are Ethereum , BNB and Polygon!");
1676
- }
1677
- if (programId) {
1678
- this.programId = programId;
1679
- } else {
1680
- switch (chain) {
1681
- case IChain.Ethereum:
1682
- this.programId = ETHEREUM_PROGRAM_IDS[cluster];
1683
- break;
1684
- case IChain.BNB:
1685
- this.programId = BNB_PROGRAM_IDS[cluster];
1686
- break;
1687
- case IChain.Polygon:
1688
- this.programId = POLYGON_PROGRAM_IDS[cluster];
1689
- break;
1690
- }
1691
- }
1692
- this.provider = new ethers.providers.JsonRpcProvider(clusterUrl);
1693
- this.signer = signer;
1694
- const baseContract = new ethers.Contract(this.programId, abi_default);
1695
- this.readContract = baseContract.connect(this.provider);
1696
- this.writeContract = baseContract.connect(this.signer);
1697
- }
1698
- async create(streamData) {
1699
- const multiParams = {
1700
- ...streamData,
1701
- recipients: [streamData]
1702
- };
1703
- const fees = await this.readContract.getWithdrawalFees(...this.getFeeParams(multiParams));
1704
- const args = (await this.generateMultiPayloads(multiParams))[0];
1705
- const sum = streamData.amount.mul(new BN4(BASE_FEE)).div(new BN4(1e6));
1706
- await this.approveTokens(streamData.tokenId, sum);
1707
- const result = await this.writeContract.create(...args, {
1708
- value: fees.value
1709
- });
1710
- const confirmedTx = await result.wait();
1711
- const metadataId = this.formatMetadataId(
1712
- confirmedTx.events.find((item) => item.event === "ContractCreated").args[0]
1713
- );
1714
- return {
1715
- ixs: [],
1716
- txId: result.hash,
1717
- metadataId
1718
- };
1719
- }
1720
- async createMultiple(multipleStreamData) {
1721
- const fees = await this.readContract.getWithdrawalFees(...this.getFeeParams(multipleStreamData));
1722
- const args = await this.generateMultiPayloads(multipleStreamData);
1723
- const sum = multipleStreamData.recipients.reduce((acc, v) => acc.add(v.amount), new BN4(0)).mul(new BN4(BASE_FEE)).div(new BN4(1e6));
1724
- await this.approveTokens(multipleStreamData.tokenId, sum);
1725
- const creationPromises = args.map((item) => this.writeContract.create(...item, { value: fees.value }));
1726
- const signatures = [];
1727
- const results = await Promise.all(creationPromises);
1728
- const confirmations = await Promise.allSettled(results.map((result) => result.wait()));
1729
- const successes = confirmations.filter((el) => el.status === "fulfilled").map((el) => el.value);
1730
- signatures.push(...successes.map((el) => el.hash));
1731
- const metadatas = confirmations.map(
1732
- (result) => result.status === "fulfilled" ? this.formatMetadataId(
1733
- result.value.events.find((item) => item.event === "ContractCreated").args[0]
1734
- ) : null
1735
- );
1736
- const metadataToRecipient = metadatas.reduce(
1737
- (acc, value, index) => {
1738
- if (value) {
1739
- acc[value] = multipleStreamData.recipients[index];
1740
- }
1741
- return acc;
1742
- },
1743
- {}
1744
- );
1745
- const failures = confirmations.filter((el) => el.status === "rejected").map((el) => el.reason);
1746
- return {
1747
- txs: signatures,
1748
- metadatas: metadatas.filter(Boolean),
1749
- metadataToRecipient,
1750
- errors: failures
1751
- };
1752
- }
1753
- async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }) {
1754
- const result = await this.writeContract.withdraw(id, amount.toString());
1755
- return {
1756
- ixs: [],
1757
- txId: result.hash
1758
- };
1759
- }
1760
- async cancel(cancelData) {
1761
- const result = await this.writeContract.cancel(cancelData.id);
1762
- return {
1763
- ixs: [],
1764
- txId: result.hash
1765
- };
1766
- }
1767
- async transfer(transferData) {
1768
- const result = await this.writeContract.transfer(transferData.id, transferData.newRecipient);
1769
- return {
1770
- ixs: [],
1771
- txId: result.hash
1772
- };
1773
- }
1774
- async topup(topupData) {
1775
- const fees = await this.readContract.getTopUpWithdrawalFees(topupData.id, topupData.amount.toString());
1776
- const sum = topupData.amount.mul(new BN4(BASE_FEE)).div(new BN4(1e6));
1777
- const stream = await this.getOne({ id: topupData.id });
1778
- await this.approveTokens(stream.mint, sum);
1779
- const result = await this.writeContract.topUp(topupData.id, topupData.amount.toString(), {
1780
- value: fees.value
1781
- });
1782
- return {
1783
- ixs: [],
1784
- txId: result.hash
1785
- };
1786
- }
1787
- async update(updateData) {
1788
- const result = await this.writeContract.update(
1789
- updateData.id,
1790
- updateData.enableAutomaticWithdrawal ? [true] : [],
1791
- updateData.withdrawFrequency ? [updateData.withdrawFrequency.toString()] : [],
1792
- updateData.amountPerPeriod ? [updateData.amountPerPeriod.toString()] : []
1793
- );
1794
- return {
1795
- ixs: [],
1796
- txId: result.hash
1797
- };
1798
- }
1799
- async getOne({ id }) {
1800
- const result = await this.readContract.getById(id);
1801
- return new EvmContract(result);
1802
- }
1803
- async get({
1804
- address,
1805
- // type = StreamType.All,
1806
- direction = "all" /* All */
1807
- }) {
1808
- const addresses = [];
1809
- if (direction === "all" /* All */ || direction === "outgoing" /* Outgoing */) {
1810
- const senderAddresses = await this.readContract.getBySender(address);
1811
- addresses.push(...senderAddresses);
1812
- }
1813
- if (direction === "all" /* All */ || direction === "incoming" /* Incoming */) {
1814
- const recipientAddresses = await this.readContract.getByRecipient(address);
1815
- addresses.push(...recipientAddresses);
1816
- }
1817
- const uniqueAddresses = [...new Set(addresses)];
1818
- const results = await this.readContract.getMultiple(uniqueAddresses);
1819
- return results.map((result, index) => [uniqueAddresses[index], new EvmContract(result)]);
1820
- }
1821
- extractErrorCode(err) {
1822
- return extractEvmErrorCode(err.toString() ?? "Unknown error!");
1823
- }
1824
- async getFees({ address }) {
1825
- const fees = await this.readContract.getFees(address);
1826
- if (!fees.exists) {
1827
- return null;
1828
- }
1829
- return {
1830
- streamflowFee: fees.streamflow_fee.toNumber() / 100,
1831
- partnerFee: fees.partner_fee.toNumber() / 100
1832
- };
1833
- }
1834
- async getDefaultStreamflowFee() {
1835
- const fee = await this.readContract.getStreamflowFees();
1836
- return fee.toNumber() / 100;
1837
- }
1838
- /**
1839
- * Returns StreamClient protocol program ID.
1840
- */
1841
- getProgramId() {
1842
- return this.programId;
1843
- }
1844
- async approveTokens(tokenId, amount) {
1845
- const tokenContract = new ethers.Contract(tokenId, ercAbi_default, this.signer);
1846
- const address = await this.signer.getAddress();
1847
- const allowance = await tokenContract.allowance(address, this.programId);
1848
- if (new BN4(allowance.toString()).gte(amount)) {
1849
- return;
1850
- }
1851
- const approvalTx = await tokenContract.approve(this.programId, amount.toString());
1852
- await approvalTx.wait();
1853
- }
1854
- // Utility function to prepare transaction payloads for multiple recipients.
1855
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1856
- async generateMultiPayloads(multipleStreamData) {
1857
- const sender = await this.signer.getAddress();
1858
- return multipleStreamData.recipients.map((recipient) => {
1859
- return [
1860
- multipleStreamData.tokenId,
1861
- recipient.amount.toString(),
1862
- multipleStreamData.period,
1863
- recipient.amountPerPeriod.toString(),
1864
- multipleStreamData.start,
1865
- recipient.cliffAmount.toString(),
1866
- [
1867
- multipleStreamData.cancelableBySender,
1868
- multipleStreamData.cancelableByRecipient,
1869
- multipleStreamData.transferableBySender,
1870
- multipleStreamData.transferableByRecipient,
1871
- multipleStreamData.canTopup,
1872
- multipleStreamData.canPause || false,
1873
- multipleStreamData.canUpdateRate || false,
1874
- multipleStreamData.automaticWithdrawal || false,
1875
- multipleStreamData.withdrawalFrequency || 0,
1876
- recipient.name
1877
- ],
1878
- recipient.recipient,
1879
- multipleStreamData.partner || sender
1880
- ];
1881
- });
1882
- }
1883
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1884
- getFeeParams(multipleStreamData) {
1885
- return [
1886
- multipleStreamData.recipients[0].amount.toString(),
1887
- multipleStreamData.period,
1888
- multipleStreamData.recipients[0].amountPerPeriod.toString(),
1889
- multipleStreamData.start,
1890
- multipleStreamData.recipients[0].cliffAmount.toString(),
1891
- multipleStreamData.automaticWithdrawal || false,
1892
- multipleStreamData.withdrawalFrequency || 0
1893
- ];
1894
- }
1895
- formatMetadataId(id) {
1896
- return toChecksumAddress(`0x${id.slice(-40)}`);
1897
- }
1898
- };
1899
-
1900
- export { EvmContract, EvmStreamClient, constants_exports as constants, EvmStreamClient as default, ercAbi_default as ercAbi, extractEvmErrorCode };
1901
- //# sourceMappingURL=index.js.map
1902
- //# sourceMappingURL=index.js.map