@@ -11,9 +11,14 @@ import { RLNContractInitOptions } from "./types.js";
11
11
12
12
const log = new Logger ( "waku:rln:contract" ) ;
13
13
14
- export class RLNContract extends RLNBaseContract {
14
+ export class RLNContract {
15
15
private instance : RLNInstance ;
16
16
private merkleRootTracker : MerkleRootTracker ;
17
+ private base : RLNBaseContract ;
18
+ private _members : Map <
19
+ number ,
20
+ { index : ethers . BigNumber ; idCommitment : string }
21
+ > ;
17
22
18
23
/**
19
24
* Asynchronous initializer for RLNContract.
@@ -23,24 +28,121 @@ export class RLNContract extends RLNBaseContract {
23
28
rlnInstance : RLNInstance ,
24
29
options : RLNContractInitOptions
25
30
) : Promise < RLNContract > {
26
- const rlnContract = new RLNContract ( rlnInstance , options ) ;
27
-
31
+ const base = await RLNBaseContract . create ( options ) ;
32
+ const rlnContract = new RLNContract ( rlnInstance , base ) ;
28
33
return rlnContract ;
29
34
}
30
35
31
- private constructor (
32
- rlnInstance : RLNInstance ,
33
- options : RLNContractInitOptions
34
- ) {
35
- super ( options ) ;
36
-
36
+ private constructor ( rlnInstance : RLNInstance , base : RLNBaseContract ) {
37
37
this . instance = rlnInstance ;
38
-
38
+ this . base = base ;
39
+ this . _members = new Map ( ) ;
39
40
const initialRoot = rlnInstance . zerokit . getMerkleRoot ( ) ;
40
41
this . merkleRootTracker = new MerkleRootTracker ( 5 , initialRoot ) ;
42
+ this . base . contract . on ( "MembershipRegistered" , ( ...args ) => {
43
+ const event = args [ args . length - 1 ] ;
44
+ this . processEvents ( [ event ] ) ;
45
+ } ) ;
46
+ this . base . contract . on ( "MembershipErased" , ( ...args ) => {
47
+ const event = args [ args . length - 1 ] ;
48
+ this . processEvents ( [ event ] ) ;
49
+ } ) ;
50
+ this . base . contract . on ( "MembershipExpired" , ( ...args ) => {
51
+ const event = args [ args . length - 1 ] ;
52
+ this . processEvents ( [ event ] ) ;
53
+ } ) ;
54
+ }
55
+
56
+ public get contract ( ) : ethers . Contract {
57
+ return this . base . contract ;
58
+ }
59
+ public get members ( ) : { index : ethers . BigNumber ; idCommitment : string } [ ] {
60
+ return Array . from ( this . _members . values ( ) ) ;
61
+ }
62
+ public get address ( ) : string {
63
+ return this . base . address ;
64
+ }
65
+ public get provider ( ) : ethers . providers . Provider {
66
+ return this . base . provider ;
67
+ }
68
+ public getRateLimit ( ) : number {
69
+ return this . base . getRateLimit ( ) ;
70
+ }
71
+ public getMinRateLimit ( ) : number {
72
+ return this . base . getMinRateLimit ( ) ;
73
+ }
74
+ public getMaxRateLimit ( ) : number {
75
+ return this . base . getMaxRateLimit ( ) ;
76
+ }
77
+ public async getMaxTotalRateLimit ( ) : Promise < number > {
78
+ return this . base . getMaxTotalRateLimit ( ) ;
79
+ }
80
+ public async getCurrentTotalRateLimit ( ) : Promise < number > {
81
+ return this . base . getCurrentTotalRateLimit ( ) ;
82
+ }
83
+ public async getRemainingTotalRateLimit ( ) : Promise < number > {
84
+ return this . base . getRemainingTotalRateLimit ( ) ;
85
+ }
86
+ public setRateLimit ( newRateLimit : number ) : void {
87
+ this . base . setRateLimit ( newRateLimit ) ;
88
+ }
89
+ public async fetchMembers ( options = { } ) : Promise < void > {
90
+ await this . base . fetchMembers ( options ) ;
91
+ }
92
+ public async getMembershipInfo ( idCommitmentBigInt : bigint ) : Promise < any > {
93
+ return this . base . getMembershipInfo ( idCommitmentBigInt ) ;
94
+ }
95
+ public async extendMembership (
96
+ idCommitmentBigInt : bigint
97
+ ) : Promise < ethers . ContractTransaction > {
98
+ return this . base . extendMembership ( idCommitmentBigInt ) ;
99
+ }
100
+ public async eraseMembership (
101
+ idCommitmentBigInt : bigint ,
102
+ eraseFromMembershipSet = true
103
+ ) : Promise < ethers . ContractTransaction > {
104
+ return this . base . eraseMembership (
105
+ idCommitmentBigInt ,
106
+ eraseFromMembershipSet
107
+ ) ;
108
+ }
109
+ public async registerMembership (
110
+ idCommitmentBigInt : bigint ,
111
+ rateLimit : number
112
+ ) : Promise < ethers . ContractTransaction > {
113
+ return this . base . registerMembership ( idCommitmentBigInt , rateLimit ) ;
114
+ }
115
+ public async withdraw ( token : string , walletAddress : string ) : Promise < void > {
116
+ return this . base . withdraw ( token , walletAddress ) ;
117
+ }
118
+ public async registerWithIdentity ( identity : any ) : Promise < any > {
119
+ return this . base . registerWithIdentity ( identity ) ;
120
+ }
121
+ public async registerWithPermitAndErase (
122
+ identity : any ,
123
+ permit : any ,
124
+ idCommitmentsToErase : string [ ]
125
+ ) : Promise < any > {
126
+ return this . base . registerWithPermitAndErase (
127
+ identity ,
128
+ permit ,
129
+ idCommitmentsToErase
130
+ ) ;
131
+ }
132
+ public async getMembershipStatus (
133
+ idCommitment : bigint
134
+ ) : Promise < "expired" | "grace" | "active" > {
135
+ return this . base . getMembershipStatus ( idCommitment ) ;
136
+ }
137
+ public async isExpired ( idCommitmentBigInt : bigint ) : Promise < boolean > {
138
+ return this . base . isExpired ( idCommitmentBigInt ) ;
139
+ }
140
+ public async isInGracePeriod ( idCommitmentBigInt : bigint ) : Promise < boolean > {
141
+ return this . base . isInGracePeriod ( idCommitmentBigInt ) ;
41
142
}
42
143
43
- public override processEvents ( events : ethers . Event [ ] ) : void {
144
+ // RLNContract-specific event processing
145
+ public processEvents ( events : ethers . Event [ ] ) : void {
44
146
const toRemoveTable = new Map < number , number [ ] > ( ) ;
45
147
const toInsertTable = new Map < number , ethers . Event [ ] > ( ) ;
46
148
0 commit comments