@gitmyabi/erc20predicate 1.0.0

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.
@@ -0,0 +1,796 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERC20Predicate_json = exports.ERC20Predicate_jsonAbi = void 0;
4
+ const viem_1 = require("viem");
5
+ /**
6
+ * ERC20Predicate_json ABI
7
+ *
8
+ * This ABI is typed using viem's type system for full type safety.
9
+ */
10
+ exports.ERC20Predicate_jsonAbi = [
11
+ {
12
+ "inputs": [],
13
+ "stateMutability": "nonpayable",
14
+ "type": "constructor"
15
+ },
16
+ {
17
+ "anonymous": false,
18
+ "inputs": [
19
+ {
20
+ "indexed": true,
21
+ "internalType": "address",
22
+ "name": "exitor",
23
+ "type": "address"
24
+ },
25
+ {
26
+ "indexed": true,
27
+ "internalType": "address",
28
+ "name": "rootToken",
29
+ "type": "address"
30
+ },
31
+ {
32
+ "indexed": false,
33
+ "internalType": "uint256",
34
+ "name": "amount",
35
+ "type": "uint256"
36
+ }
37
+ ],
38
+ "name": "ExitedERC20",
39
+ "type": "event"
40
+ },
41
+ {
42
+ "anonymous": false,
43
+ "inputs": [
44
+ {
45
+ "indexed": true,
46
+ "internalType": "address",
47
+ "name": "depositor",
48
+ "type": "address"
49
+ },
50
+ {
51
+ "indexed": true,
52
+ "internalType": "address",
53
+ "name": "depositReceiver",
54
+ "type": "address"
55
+ },
56
+ {
57
+ "indexed": true,
58
+ "internalType": "address",
59
+ "name": "rootToken",
60
+ "type": "address"
61
+ },
62
+ {
63
+ "indexed": false,
64
+ "internalType": "uint256",
65
+ "name": "amount",
66
+ "type": "uint256"
67
+ }
68
+ ],
69
+ "name": "LockedERC20",
70
+ "type": "event"
71
+ },
72
+ {
73
+ "anonymous": false,
74
+ "inputs": [
75
+ {
76
+ "indexed": true,
77
+ "internalType": "bytes32",
78
+ "name": "role",
79
+ "type": "bytes32"
80
+ },
81
+ {
82
+ "indexed": true,
83
+ "internalType": "bytes32",
84
+ "name": "previousAdminRole",
85
+ "type": "bytes32"
86
+ },
87
+ {
88
+ "indexed": true,
89
+ "internalType": "bytes32",
90
+ "name": "newAdminRole",
91
+ "type": "bytes32"
92
+ }
93
+ ],
94
+ "name": "RoleAdminChanged",
95
+ "type": "event"
96
+ },
97
+ {
98
+ "anonymous": false,
99
+ "inputs": [
100
+ {
101
+ "indexed": true,
102
+ "internalType": "bytes32",
103
+ "name": "role",
104
+ "type": "bytes32"
105
+ },
106
+ {
107
+ "indexed": true,
108
+ "internalType": "address",
109
+ "name": "account",
110
+ "type": "address"
111
+ },
112
+ {
113
+ "indexed": true,
114
+ "internalType": "address",
115
+ "name": "sender",
116
+ "type": "address"
117
+ }
118
+ ],
119
+ "name": "RoleGranted",
120
+ "type": "event"
121
+ },
122
+ {
123
+ "anonymous": false,
124
+ "inputs": [
125
+ {
126
+ "indexed": true,
127
+ "internalType": "bytes32",
128
+ "name": "role",
129
+ "type": "bytes32"
130
+ },
131
+ {
132
+ "indexed": true,
133
+ "internalType": "address",
134
+ "name": "account",
135
+ "type": "address"
136
+ },
137
+ {
138
+ "indexed": true,
139
+ "internalType": "address",
140
+ "name": "sender",
141
+ "type": "address"
142
+ }
143
+ ],
144
+ "name": "RoleRevoked",
145
+ "type": "event"
146
+ },
147
+ {
148
+ "inputs": [],
149
+ "name": "DEFAULT_ADMIN_ROLE",
150
+ "outputs": [
151
+ {
152
+ "internalType": "bytes32",
153
+ "name": "",
154
+ "type": "bytes32"
155
+ }
156
+ ],
157
+ "stateMutability": "view",
158
+ "type": "function"
159
+ },
160
+ {
161
+ "inputs": [],
162
+ "name": "MANAGER_ROLE",
163
+ "outputs": [
164
+ {
165
+ "internalType": "bytes32",
166
+ "name": "",
167
+ "type": "bytes32"
168
+ }
169
+ ],
170
+ "stateMutability": "view",
171
+ "type": "function"
172
+ },
173
+ {
174
+ "inputs": [],
175
+ "name": "TOKEN_TYPE",
176
+ "outputs": [
177
+ {
178
+ "internalType": "bytes32",
179
+ "name": "",
180
+ "type": "bytes32"
181
+ }
182
+ ],
183
+ "stateMutability": "view",
184
+ "type": "function"
185
+ },
186
+ {
187
+ "inputs": [],
188
+ "name": "TRANSFER_EVENT_SIG",
189
+ "outputs": [
190
+ {
191
+ "internalType": "bytes32",
192
+ "name": "",
193
+ "type": "bytes32"
194
+ }
195
+ ],
196
+ "stateMutability": "view",
197
+ "type": "function"
198
+ },
199
+ {
200
+ "inputs": [
201
+ {
202
+ "internalType": "address",
203
+ "name": "",
204
+ "type": "address"
205
+ },
206
+ {
207
+ "internalType": "address",
208
+ "name": "rootToken",
209
+ "type": "address"
210
+ },
211
+ {
212
+ "internalType": "bytes",
213
+ "name": "log",
214
+ "type": "bytes"
215
+ }
216
+ ],
217
+ "name": "exitTokens",
218
+ "outputs": [],
219
+ "stateMutability": "nonpayable",
220
+ "type": "function"
221
+ },
222
+ {
223
+ "inputs": [
224
+ {
225
+ "internalType": "bytes32",
226
+ "name": "role",
227
+ "type": "bytes32"
228
+ }
229
+ ],
230
+ "name": "getRoleAdmin",
231
+ "outputs": [
232
+ {
233
+ "internalType": "bytes32",
234
+ "name": "",
235
+ "type": "bytes32"
236
+ }
237
+ ],
238
+ "stateMutability": "view",
239
+ "type": "function"
240
+ },
241
+ {
242
+ "inputs": [
243
+ {
244
+ "internalType": "bytes32",
245
+ "name": "role",
246
+ "type": "bytes32"
247
+ },
248
+ {
249
+ "internalType": "uint256",
250
+ "name": "index",
251
+ "type": "uint256"
252
+ }
253
+ ],
254
+ "name": "getRoleMember",
255
+ "outputs": [
256
+ {
257
+ "internalType": "address",
258
+ "name": "",
259
+ "type": "address"
260
+ }
261
+ ],
262
+ "stateMutability": "view",
263
+ "type": "function"
264
+ },
265
+ {
266
+ "inputs": [
267
+ {
268
+ "internalType": "bytes32",
269
+ "name": "role",
270
+ "type": "bytes32"
271
+ }
272
+ ],
273
+ "name": "getRoleMemberCount",
274
+ "outputs": [
275
+ {
276
+ "internalType": "uint256",
277
+ "name": "",
278
+ "type": "uint256"
279
+ }
280
+ ],
281
+ "stateMutability": "view",
282
+ "type": "function"
283
+ },
284
+ {
285
+ "inputs": [
286
+ {
287
+ "internalType": "bytes32",
288
+ "name": "role",
289
+ "type": "bytes32"
290
+ },
291
+ {
292
+ "internalType": "address",
293
+ "name": "account",
294
+ "type": "address"
295
+ }
296
+ ],
297
+ "name": "grantRole",
298
+ "outputs": [],
299
+ "stateMutability": "nonpayable",
300
+ "type": "function"
301
+ },
302
+ {
303
+ "inputs": [
304
+ {
305
+ "internalType": "bytes32",
306
+ "name": "role",
307
+ "type": "bytes32"
308
+ },
309
+ {
310
+ "internalType": "address",
311
+ "name": "account",
312
+ "type": "address"
313
+ }
314
+ ],
315
+ "name": "hasRole",
316
+ "outputs": [
317
+ {
318
+ "internalType": "bool",
319
+ "name": "",
320
+ "type": "bool"
321
+ }
322
+ ],
323
+ "stateMutability": "view",
324
+ "type": "function"
325
+ },
326
+ {
327
+ "inputs": [
328
+ {
329
+ "internalType": "address",
330
+ "name": "_owner",
331
+ "type": "address"
332
+ }
333
+ ],
334
+ "name": "initialize",
335
+ "outputs": [],
336
+ "stateMutability": "nonpayable",
337
+ "type": "function"
338
+ },
339
+ {
340
+ "inputs": [
341
+ {
342
+ "internalType": "address",
343
+ "name": "depositor",
344
+ "type": "address"
345
+ },
346
+ {
347
+ "internalType": "address",
348
+ "name": "depositReceiver",
349
+ "type": "address"
350
+ },
351
+ {
352
+ "internalType": "address",
353
+ "name": "rootToken",
354
+ "type": "address"
355
+ },
356
+ {
357
+ "internalType": "bytes",
358
+ "name": "depositData",
359
+ "type": "bytes"
360
+ }
361
+ ],
362
+ "name": "lockTokens",
363
+ "outputs": [],
364
+ "stateMutability": "nonpayable",
365
+ "type": "function"
366
+ },
367
+ {
368
+ "inputs": [
369
+ {
370
+ "internalType": "address",
371
+ "name": "target",
372
+ "type": "address"
373
+ },
374
+ {
375
+ "internalType": "bytes",
376
+ "name": "data",
377
+ "type": "bytes"
378
+ }
379
+ ],
380
+ "name": "migrateTokens",
381
+ "outputs": [],
382
+ "stateMutability": "nonpayable",
383
+ "type": "function"
384
+ },
385
+ {
386
+ "inputs": [
387
+ {
388
+ "internalType": "bytes32",
389
+ "name": "role",
390
+ "type": "bytes32"
391
+ },
392
+ {
393
+ "internalType": "address",
394
+ "name": "account",
395
+ "type": "address"
396
+ }
397
+ ],
398
+ "name": "renounceRole",
399
+ "outputs": [],
400
+ "stateMutability": "nonpayable",
401
+ "type": "function"
402
+ },
403
+ {
404
+ "inputs": [
405
+ {
406
+ "internalType": "bytes32",
407
+ "name": "role",
408
+ "type": "bytes32"
409
+ },
410
+ {
411
+ "internalType": "address",
412
+ "name": "account",
413
+ "type": "address"
414
+ }
415
+ ],
416
+ "name": "revokeRole",
417
+ "outputs": [],
418
+ "stateMutability": "nonpayable",
419
+ "type": "function"
420
+ }
421
+ ];
422
+ /**
423
+ * ERC20Predicate_json Contract Class
424
+ *
425
+ * Provides a class-based API similar to TypeChain for interacting with the contract.
426
+ *
427
+ * @example
428
+ * ```typescript
429
+ * import { createPublicClient, createWalletClient, http } from 'viem';
430
+ * import { mainnet } from 'viem/chains';
431
+ * import { ERC20Predicate_json } from 'ERC20Predicate_json';
432
+ *
433
+ * const publicClient = createPublicClient({ chain: mainnet, transport: http() });
434
+ * const walletClient = createWalletClient({ chain: mainnet, transport: http() });
435
+ *
436
+ * const contract = new ERC20Predicate_json('0x...', { publicClient, walletClient });
437
+ *
438
+ * // Read functions
439
+ * const result = await contract.balanceOf('0x...');
440
+ *
441
+ * // Write functions
442
+ * const hash = await contract.transfer('0x...', 1000n);
443
+ *
444
+ * // Simulate transactions (dry-run)
445
+ * const simulation = await contract.simulate.transfer('0x...', 1000n);
446
+ * console.log('Gas estimate:', simulation.request.gas);
447
+ *
448
+ * // Watch events
449
+ * const unwatch = contract.watch.Transfer((event) => {
450
+ * console.log('Transfer event:', event);
451
+ * });
452
+ * ```
453
+ */
454
+ class ERC20Predicate_json {
455
+ constructor(address, clients) {
456
+ this.contractAddress = address;
457
+ this.publicClient = clients.publicClient;
458
+ this.contract = (0, viem_1.getContract)({
459
+ address,
460
+ abi: exports.ERC20Predicate_jsonAbi,
461
+ client: {
462
+ public: clients.publicClient,
463
+ wallet: clients.walletClient,
464
+ },
465
+ });
466
+ }
467
+ /**
468
+ * Get the contract address
469
+ */
470
+ get address() {
471
+ return this.contractAddress;
472
+ }
473
+ /**
474
+ * Get the underlying viem contract instance
475
+ */
476
+ getContract() {
477
+ return this.contract;
478
+ }
479
+ /**
480
+ * DEFAULT_ADMIN_ROLE
481
+ * view
482
+ */
483
+ async DEFAULT_ADMIN_ROLE() {
484
+ return this.contract.read.DEFAULT_ADMIN_ROLE();
485
+ }
486
+ /**
487
+ * MANAGER_ROLE
488
+ * view
489
+ */
490
+ async MANAGER_ROLE() {
491
+ return this.contract.read.MANAGER_ROLE();
492
+ }
493
+ /**
494
+ * TOKEN_TYPE
495
+ * view
496
+ */
497
+ async TOKEN_TYPE() {
498
+ return this.contract.read.TOKEN_TYPE();
499
+ }
500
+ /**
501
+ * TRANSFER_EVENT_SIG
502
+ * view
503
+ */
504
+ async TRANSFER_EVENT_SIG() {
505
+ return this.contract.read.TRANSFER_EVENT_SIG();
506
+ }
507
+ /**
508
+ * getRoleAdmin
509
+ * view
510
+ */
511
+ async getRoleAdmin(role) {
512
+ return this.contract.read.getRoleAdmin([role]);
513
+ }
514
+ /**
515
+ * getRoleMember
516
+ * view
517
+ */
518
+ async getRoleMember(role, index) {
519
+ return this.contract.read.getRoleMember([role, index]);
520
+ }
521
+ /**
522
+ * getRoleMemberCount
523
+ * view
524
+ */
525
+ async getRoleMemberCount(role) {
526
+ return this.contract.read.getRoleMemberCount([role]);
527
+ }
528
+ /**
529
+ * hasRole
530
+ * view
531
+ */
532
+ async hasRole(role, account) {
533
+ return this.contract.read.hasRole([role, account]);
534
+ }
535
+ /**
536
+ * exitTokens
537
+ * nonpayable
538
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
539
+ */
540
+ async exitTokens(arg0, rootToken, log, options) {
541
+ if (!this.contract.write) {
542
+ throw new Error('Wallet client is required for write operations');
543
+ }
544
+ return this.contract.write.exitTokens([arg0, rootToken, log], options);
545
+ }
546
+ /**
547
+ * grantRole
548
+ * nonpayable
549
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
550
+ */
551
+ async grantRole(role, account, options) {
552
+ if (!this.contract.write) {
553
+ throw new Error('Wallet client is required for write operations');
554
+ }
555
+ return this.contract.write.grantRole([role, account], options);
556
+ }
557
+ /**
558
+ * initialize
559
+ * nonpayable
560
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
561
+ */
562
+ async initialize(_owner, options) {
563
+ if (!this.contract.write) {
564
+ throw new Error('Wallet client is required for write operations');
565
+ }
566
+ return this.contract.write.initialize([_owner], options);
567
+ }
568
+ /**
569
+ * lockTokens
570
+ * nonpayable
571
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
572
+ */
573
+ async lockTokens(depositor, depositReceiver, rootToken, depositData, options) {
574
+ if (!this.contract.write) {
575
+ throw new Error('Wallet client is required for write operations');
576
+ }
577
+ return this.contract.write.lockTokens([depositor, depositReceiver, rootToken, depositData], options);
578
+ }
579
+ /**
580
+ * migrateTokens
581
+ * nonpayable
582
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
583
+ */
584
+ async migrateTokens(target, data, options) {
585
+ if (!this.contract.write) {
586
+ throw new Error('Wallet client is required for write operations');
587
+ }
588
+ return this.contract.write.migrateTokens([target, data], options);
589
+ }
590
+ /**
591
+ * renounceRole
592
+ * nonpayable
593
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
594
+ */
595
+ async renounceRole(role, account, options) {
596
+ if (!this.contract.write) {
597
+ throw new Error('Wallet client is required for write operations');
598
+ }
599
+ return this.contract.write.renounceRole([role, account], options);
600
+ }
601
+ /**
602
+ * revokeRole
603
+ * nonpayable
604
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
605
+ */
606
+ async revokeRole(role, account, options) {
607
+ if (!this.contract.write) {
608
+ throw new Error('Wallet client is required for write operations');
609
+ }
610
+ return this.contract.write.revokeRole([role, account], options);
611
+ }
612
+ /**
613
+ * Simulate contract write operations (dry-run without sending transaction)
614
+ *
615
+ * @example
616
+ * const result = await contract.simulate.transfer('0x...', 1000n);
617
+ * console.log('Gas estimate:', result.request.gas);
618
+ * console.log('Would succeed:', result.result);
619
+ */
620
+ get simulate() {
621
+ const contract = this.contract;
622
+ if (!contract.simulate) {
623
+ throw new Error('Public client is required for simulation');
624
+ }
625
+ return {
626
+ /**
627
+ * Simulate exitTokens
628
+ * Returns gas estimate and result without sending transaction
629
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
630
+ */
631
+ async exitTokens(arg0, rootToken, log, options) {
632
+ return contract.simulate.exitTokens([arg0, rootToken, log], options);
633
+ },
634
+ /**
635
+ * Simulate grantRole
636
+ * Returns gas estimate and result without sending transaction
637
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
638
+ */
639
+ async grantRole(role, account, options) {
640
+ return contract.simulate.grantRole([role, account], options);
641
+ },
642
+ /**
643
+ * Simulate initialize
644
+ * Returns gas estimate and result without sending transaction
645
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
646
+ */
647
+ async initialize(_owner, options) {
648
+ return contract.simulate.initialize([_owner], options);
649
+ },
650
+ /**
651
+ * Simulate lockTokens
652
+ * Returns gas estimate and result without sending transaction
653
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
654
+ */
655
+ async lockTokens(depositor, depositReceiver, rootToken, depositData, options) {
656
+ return contract.simulate.lockTokens([depositor, depositReceiver, rootToken, depositData], options);
657
+ },
658
+ /**
659
+ * Simulate migrateTokens
660
+ * Returns gas estimate and result without sending transaction
661
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
662
+ */
663
+ async migrateTokens(target, data, options) {
664
+ return contract.simulate.migrateTokens([target, data], options);
665
+ },
666
+ /**
667
+ * Simulate renounceRole
668
+ * Returns gas estimate and result without sending transaction
669
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
670
+ */
671
+ async renounceRole(role, account, options) {
672
+ return contract.simulate.renounceRole([role, account], options);
673
+ },
674
+ /**
675
+ * Simulate revokeRole
676
+ * Returns gas estimate and result without sending transaction
677
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
678
+ */
679
+ async revokeRole(role, account, options) {
680
+ return contract.simulate.revokeRole([role, account], options);
681
+ }
682
+ };
683
+ }
684
+ /**
685
+ * Watch contract events
686
+ *
687
+ * @example
688
+ * // Watch all Transfer events
689
+ * const unwatch = contract.watch.Transfer((event) => {
690
+ * console.log('Transfer:', event);
691
+ * });
692
+ *
693
+ * // Stop watching
694
+ * unwatch();
695
+ */
696
+ get watch() {
697
+ return {
698
+ /**
699
+ * Watch ExitedERC20 events
700
+ * @param callback Function to call when event is emitted
701
+ * @param filter Optional filter for indexed parameters
702
+ * @returns Unwatch function to stop listening
703
+ */
704
+ ExitedERC20: (callback, filter) => {
705
+ return this.publicClient.watchContractEvent({
706
+ address: this.contractAddress,
707
+ abi: exports.ERC20Predicate_jsonAbi,
708
+ eventName: 'ExitedERC20',
709
+ args: filter,
710
+ onLogs: (logs) => {
711
+ logs.forEach((log) => {
712
+ callback(log.args);
713
+ });
714
+ },
715
+ });
716
+ },
717
+ /**
718
+ * Watch LockedERC20 events
719
+ * @param callback Function to call when event is emitted
720
+ * @param filter Optional filter for indexed parameters
721
+ * @returns Unwatch function to stop listening
722
+ */
723
+ LockedERC20: (callback, filter) => {
724
+ return this.publicClient.watchContractEvent({
725
+ address: this.contractAddress,
726
+ abi: exports.ERC20Predicate_jsonAbi,
727
+ eventName: 'LockedERC20',
728
+ args: filter,
729
+ onLogs: (logs) => {
730
+ logs.forEach((log) => {
731
+ callback(log.args);
732
+ });
733
+ },
734
+ });
735
+ },
736
+ /**
737
+ * Watch RoleAdminChanged events
738
+ * @param callback Function to call when event is emitted
739
+ * @param filter Optional filter for indexed parameters
740
+ * @returns Unwatch function to stop listening
741
+ */
742
+ RoleAdminChanged: (callback, filter) => {
743
+ return this.publicClient.watchContractEvent({
744
+ address: this.contractAddress,
745
+ abi: exports.ERC20Predicate_jsonAbi,
746
+ eventName: 'RoleAdminChanged',
747
+ args: filter,
748
+ onLogs: (logs) => {
749
+ logs.forEach((log) => {
750
+ callback(log.args);
751
+ });
752
+ },
753
+ });
754
+ },
755
+ /**
756
+ * Watch RoleGranted events
757
+ * @param callback Function to call when event is emitted
758
+ * @param filter Optional filter for indexed parameters
759
+ * @returns Unwatch function to stop listening
760
+ */
761
+ RoleGranted: (callback, filter) => {
762
+ return this.publicClient.watchContractEvent({
763
+ address: this.contractAddress,
764
+ abi: exports.ERC20Predicate_jsonAbi,
765
+ eventName: 'RoleGranted',
766
+ args: filter,
767
+ onLogs: (logs) => {
768
+ logs.forEach((log) => {
769
+ callback(log.args);
770
+ });
771
+ },
772
+ });
773
+ },
774
+ /**
775
+ * Watch RoleRevoked events
776
+ * @param callback Function to call when event is emitted
777
+ * @param filter Optional filter for indexed parameters
778
+ * @returns Unwatch function to stop listening
779
+ */
780
+ RoleRevoked: (callback, filter) => {
781
+ return this.publicClient.watchContractEvent({
782
+ address: this.contractAddress,
783
+ abi: exports.ERC20Predicate_jsonAbi,
784
+ eventName: 'RoleRevoked',
785
+ args: filter,
786
+ onLogs: (logs) => {
787
+ logs.forEach((log) => {
788
+ callback(log.args);
789
+ });
790
+ },
791
+ });
792
+ }
793
+ };
794
+ }
795
+ }
796
+ exports.ERC20Predicate_json = ERC20Predicate_json;