@@ -25,6 +25,8 @@ type ContractBindings struct {
25
25
BlsApkRegistryAddr gethcommon.Address
26
26
OperatorStateRetrieverAddr gethcommon.Address
27
27
IndexRegistryAddr gethcommon.Address
28
+ DelegationManagerAddr gethcommon.Address
29
+ AvsDirectoryAddr gethcommon.Address
28
30
// contract bindings
29
31
ServiceManager * servicemanager.ContractServiceManagerBase
30
32
RegistryCoordinator * regcoordinator.ContractRegistryCoordinator
@@ -34,6 +36,8 @@ type ContractBindings struct {
34
36
OperatorStateRetriever * opstateretriever.ContractOperatorStateRetriever
35
37
}
36
38
39
+ // NewAVSRegistryContractBindings creates a new instance of ContractBindings
40
+ // Deprecated: Use NewBindingsFromConfig instead
37
41
func NewAVSRegistryContractBindings (
38
42
registryCoordinatorAddr gethcommon.Address ,
39
43
operatorStateRetrieverAddr gethcommon.Address ,
@@ -116,3 +120,130 @@ func NewAVSRegistryContractBindings(
116
120
OperatorStateRetriever : contractOperatorStateRetriever ,
117
121
}, nil
118
122
}
123
+
124
+ // NewBindingsFromConfig creates a new instance of ContractBindings
125
+ func NewBindingsFromConfig (
126
+ cfg Config ,
127
+ client eth.Client ,
128
+ logger logging.Logger ,
129
+ ) (* ContractBindings , error ) {
130
+ var (
131
+ err error
132
+
133
+ serviceManagerAddr gethcommon.Address
134
+ registryCoordinatorAddr gethcommon.Address
135
+ stakeRegistryAddr gethcommon.Address
136
+ blsApkRegistryAddr gethcommon.Address
137
+ indexRegistryAddr gethcommon.Address
138
+ operatorStateRetrieverAddr gethcommon.Address
139
+ delegationManagerAddr gethcommon.Address
140
+ avsDirectoryAddr gethcommon.Address
141
+
142
+ contractBlsRegistryCoordinator * regcoordinator.ContractRegistryCoordinator
143
+ contractServiceManager * servicemanager.ContractServiceManagerBase
144
+ contractStakeRegistry * stakeregistry.ContractStakeRegistry
145
+ contractBlsApkRegistry * blsapkregistry.ContractBLSApkRegistry
146
+ contractIndexRegistry * indexregistry.ContractIndexRegistry
147
+ contractOperatorStateRetriever * opstateretriever.ContractOperatorStateRetriever
148
+ )
149
+
150
+ if isZeroAddress (cfg .RegistryCoordinatorAddress ) {
151
+ logger .Warn ("RegistryCoordinator address not provided, the calls to the contract will not work" )
152
+ } else {
153
+ contractBlsRegistryCoordinator , err = regcoordinator .NewContractRegistryCoordinator (
154
+ cfg .RegistryCoordinatorAddress ,
155
+ client ,
156
+ )
157
+ if err != nil {
158
+ return nil , utils .WrapError ("Failed to create BLSRegistryCoordinator contract" , err )
159
+ }
160
+
161
+ serviceManagerAddr , err = contractBlsRegistryCoordinator .ServiceManager (& bind.CallOpts {})
162
+ if err != nil {
163
+ return nil , utils .WrapError ("Failed to fetch ServiceManager address" , err )
164
+ }
165
+ contractServiceManager , err = servicemanager .NewContractServiceManagerBase (
166
+ serviceManagerAddr ,
167
+ client ,
168
+ )
169
+ if err != nil {
170
+ return nil , utils .WrapError ("Failed to create ServiceManager contract" , err )
171
+ }
172
+
173
+ stakeRegistryAddr , err = contractBlsRegistryCoordinator .StakeRegistry (& bind.CallOpts {})
174
+ if err != nil {
175
+ return nil , utils .WrapError ("Failed to fetch StakeRegistry address" , err )
176
+ }
177
+ contractStakeRegistry , err = stakeregistry .NewContractStakeRegistry (
178
+ stakeRegistryAddr ,
179
+ client ,
180
+ )
181
+ if err != nil {
182
+ return nil , utils .WrapError ("Failed to create StakeRegistry contract" , err )
183
+ }
184
+
185
+ blsApkRegistryAddr , err = contractBlsRegistryCoordinator .BlsApkRegistry (& bind.CallOpts {})
186
+ if err != nil {
187
+ return nil , utils .WrapError ("Failed to fetch BLSPubkeyRegistry address" , err )
188
+ }
189
+ contractBlsApkRegistry , err = blsapkregistry .NewContractBLSApkRegistry (
190
+ blsApkRegistryAddr ,
191
+ client ,
192
+ )
193
+ if err != nil {
194
+ return nil , utils .WrapError ("Failed to create BLSPubkeyRegistry contract" , err )
195
+ }
196
+
197
+ indexRegistryAddr , err = contractBlsRegistryCoordinator .IndexRegistry (& bind.CallOpts {})
198
+ if err != nil {
199
+ return nil , utils .WrapError ("Failed to fetch IndexRegistry address" , err )
200
+ }
201
+ contractIndexRegistry , err = indexregistry .NewContractIndexRegistry (indexRegistryAddr , client )
202
+ if err != nil {
203
+ return nil , utils .WrapError ("Failed to create IndexRegistry contract" , err )
204
+ }
205
+
206
+ delegationManagerAddr , err = contractStakeRegistry .Delegation (& bind.CallOpts {})
207
+ if err != nil {
208
+ return nil , utils .WrapError ("Failed to get DelegationManager address" , err )
209
+ }
210
+ avsDirectoryAddr , err = contractServiceManager .AvsDirectory (& bind.CallOpts {})
211
+ if err != nil {
212
+ return nil , utils .WrapError ("Failed to get AvsDirectory address" , err )
213
+ }
214
+ }
215
+
216
+ if isZeroAddress (cfg .OperatorStateRetrieverAddress ) {
217
+ logger .Warn ("OperatorStateRetriever address not provided, the calls to the contract will not work" )
218
+ } else {
219
+ contractOperatorStateRetriever , err = opstateretriever .NewContractOperatorStateRetriever (
220
+ cfg .OperatorStateRetrieverAddress ,
221
+ client ,
222
+ )
223
+ if err != nil {
224
+ return nil , utils .WrapError ("Failed to fetch OperatorStateRetriever contract" , err )
225
+ }
226
+
227
+ }
228
+
229
+ return & ContractBindings {
230
+ ServiceManagerAddr : serviceManagerAddr ,
231
+ RegistryCoordinatorAddr : registryCoordinatorAddr ,
232
+ StakeRegistryAddr : stakeRegistryAddr ,
233
+ BlsApkRegistryAddr : blsApkRegistryAddr ,
234
+ IndexRegistryAddr : indexRegistryAddr ,
235
+ OperatorStateRetrieverAddr : operatorStateRetrieverAddr ,
236
+ DelegationManagerAddr : delegationManagerAddr ,
237
+ AvsDirectoryAddr : avsDirectoryAddr ,
238
+ ServiceManager : contractServiceManager ,
239
+ RegistryCoordinator : contractBlsRegistryCoordinator ,
240
+ StakeRegistry : contractStakeRegistry ,
241
+ BlsApkRegistry : contractBlsApkRegistry ,
242
+ IndexRegistry : contractIndexRegistry ,
243
+ OperatorStateRetriever : contractOperatorStateRetriever ,
244
+ }, nil
245
+ }
246
+
247
+ func isZeroAddress (address gethcommon.Address ) bool {
248
+ return address == gethcommon.Address {}
249
+ }
0 commit comments