-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathbindings.go
129 lines (117 loc) · 5.57 KB
/
bindings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Package elcontracts bindings.go contains functions that create contract bindings for the Eigenlayer Core contracts
// These functions are meant to be used by constructors of the chainio package.
package elcontracts
import (
permissioncontroller "github.com/Layr-Labs/eigensdk-go/contracts/bindings/PermissionController"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
avsdirectory "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AVSDirectory"
allocationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AllocationManager"
delegationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/DelegationManager"
rewardscoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IRewardsCoordinator"
strategymanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StrategyManager"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/utils"
)
// ContractBindings contains the contract bindings for the EigenLayer Core contracts
//
// Unclear why geth bindings don't store and expose the contract address,
// so we also store them here in case the different constructors that use this struct need them
type ContractBindings struct {
StrategyManagerAddr gethcommon.Address
DelegationManagerAddr gethcommon.Address
AvsDirectoryAddr gethcommon.Address
RewardsCoordinatorAddress gethcommon.Address
AllocationManagerAddr gethcommon.Address
DelegationManager *delegationmanager.ContractDelegationManager
StrategyManager *strategymanager.ContractStrategyManager
AvsDirectory *avsdirectory.ContractAVSDirectory
RewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
AllocationManager *allocationmanager.ContractAllocationManager
PermissionController *permissioncontroller.ContractPermissionController
}
func NewBindingsFromConfig(
cfg Config,
client eth.HttpBackend,
logger logging.Logger,
) (*ContractBindings, error) {
var (
err error
contractDelegationManager *delegationmanager.ContractDelegationManager
contractStrategyManager *strategymanager.ContractStrategyManager
contractAllocationManager *allocationmanager.ContractAllocationManager
strategyManagerAddr gethcommon.Address
allocationManagerAddr gethcommon.Address
avsDirectory *avsdirectory.ContractAVSDirectory
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
permissionController *permissioncontroller.ContractPermissionController
)
if isZeroAddress(cfg.DelegationManagerAddress) {
logger.Debug("DelegationManager address not provided, the calls to the contract will not work")
} else {
contractDelegationManager, err = delegationmanager.NewContractDelegationManager(cfg.DelegationManagerAddress, client)
if err != nil {
return nil, utils.WrapError("Failed to create DelegationManager contract", err)
}
strategyManagerAddr, err = contractDelegationManager.StrategyManager(&bind.CallOpts{})
if err != nil {
return nil, utils.WrapError("Failed to fetch StrategyManager address", err)
}
contractStrategyManager, err = strategymanager.NewContractStrategyManager(strategyManagerAddr, client)
if err != nil {
return nil, utils.WrapError("Failed to fetch StrategyManager contract", err)
}
allocationManagerAddr, err = contractDelegationManager.AllocationManager(&bind.CallOpts{})
if err != nil {
return nil, utils.WrapError("Failed to fetch AllocationManager address", err)
}
contractAllocationManager, err = allocationmanager.NewContractAllocationManager(allocationManagerAddr, client)
if err != nil {
return nil, utils.WrapError("Failed to fetch AllocationManager contract", err)
}
}
if isZeroAddress(cfg.PermissionsControllerAddress) {
logger.Debug("PermissionController address not provided, the calls to the contract will not work")
} else {
permissionController, err = permissioncontroller.NewContractPermissionController(
cfg.PermissionsControllerAddress,
client,
)
if err != nil {
return nil, utils.WrapError("Failed to fetch PermissionController contract", err)
}
}
if isZeroAddress(cfg.AvsDirectoryAddress) {
logger.Debug("AVSDirectory address not provided, the calls to the contract will not work")
} else {
avsDirectory, err = avsdirectory.NewContractAVSDirectory(cfg.AvsDirectoryAddress, client)
if err != nil {
return nil, utils.WrapError("Failed to fetch AVSDirectory contract", err)
}
}
if isZeroAddress(cfg.RewardsCoordinatorAddress) {
logger.Debug("RewardsCoordinator address not provided, the calls to the contract will not work")
} else {
rewardsCoordinator, err = rewardscoordinator.NewContractIRewardsCoordinator(cfg.RewardsCoordinatorAddress, client)
if err != nil {
return nil, utils.WrapError("Failed to fetch RewardsCoordinator contract", err)
}
}
return &ContractBindings{
StrategyManagerAddr: strategyManagerAddr,
DelegationManagerAddr: cfg.DelegationManagerAddress,
AvsDirectoryAddr: cfg.AvsDirectoryAddress,
RewardsCoordinatorAddress: cfg.RewardsCoordinatorAddress,
StrategyManager: contractStrategyManager,
DelegationManager: contractDelegationManager,
AvsDirectory: avsDirectory,
RewardsCoordinator: rewardsCoordinator,
AllocationManager: contractAllocationManager,
AllocationManagerAddr: allocationManagerAddr,
PermissionController: permissionController,
}, nil
}
func isZeroAddress(address gethcommon.Address) bool {
return address == gethcommon.Address{}
}