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