Skip to content

Commit

Permalink
feat: modularize bindings generation
Browse files Browse the repository at this point in the history
make improve

init

address comments

address comments

slashing push

working slashing

update contracts submodules

update to new AM

fix test

update to remove slasher and into AM

feat: add new funcs (#382)

Co-authored-by: Madhur Shrimal <[email protected]>

update contracts submodules

update contracts submodules

update with latest methods

rebase

update to ctx

change name

address comments

more methods
  • Loading branch information
shrimalmadhur committed Dec 3, 2024
1 parent 7d2cd16 commit 985fa2f
Show file tree
Hide file tree
Showing 21 changed files with 7,940 additions and 4,487 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ lint: ## runs all linters

___BINDINGS___: ##

core_default := "DelegationManager IRewardsCoordinator ISlasher StrategyManager EigenPod EigenPodManager IStrategy IAVSDirectory"
core_default := "DelegationManager IRewardsCoordinator StrategyManager EigenPod EigenPodManager IStrategy AVSDirectory AllocationManager"
core_location := "./lib/eigenlayer-middleware/lib/eigenlayer-contracts"
core_bindings_location := "../../../../bindings"

Expand Down
51 changes: 20 additions & 31 deletions chainio/clients/elcontracts/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
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"
avsdirectory "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IAVSDirectory"
rewardscoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IRewardsCoordinator"
slasher "github.com/Layr-Labs/eigensdk-go/contracts/bindings/ISlasher"
strategymanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StrategyManager"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/utils"
Expand All @@ -21,16 +21,16 @@ import (
// 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 {
SlasherAddr gethcommon.Address
StrategyManagerAddr gethcommon.Address
DelegationManagerAddr gethcommon.Address
AvsDirectoryAddr gethcommon.Address
RewardsCoordinatorAddress gethcommon.Address
Slasher *slasher.ContractISlasher
AllocationManagerAddr gethcommon.Address
DelegationManager *delegationmanager.ContractDelegationManager
StrategyManager *strategymanager.ContractStrategyManager
AvsDirectory *avsdirectory.ContractIAVSDirectory
AvsDirectory *avsdirectory.ContractAVSDirectory
RewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
AllocationManager *allocationmanager.ContractAllocationManager
}

func NewBindingsFromConfig(
Expand All @@ -42,11 +42,11 @@ func NewBindingsFromConfig(
err error

contractDelegationManager *delegationmanager.ContractDelegationManager
contractSlasher *slasher.ContractISlasher
contractStrategyManager *strategymanager.ContractStrategyManager
slasherAddr gethcommon.Address
contractAllocationManager *allocationmanager.ContractAllocationManager
strategyManagerAddr gethcommon.Address
avsDirectory *avsdirectory.ContractIAVSDirectory
allocationManagerAddr gethcommon.Address
avsDirectory *avsdirectory.ContractAVSDirectory
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
)

Expand All @@ -58,29 +58,29 @@ func NewBindingsFromConfig(
return nil, utils.WrapError("Failed to create DelegationManager contract", err)
}

slasherAddr, err = contractDelegationManager.Slasher(&bind.CallOpts{})
strategyManagerAddr, err = contractDelegationManager.StrategyManager(&bind.CallOpts{})
if err != nil {
return nil, utils.WrapError("Failed to fetch Slasher address", err)
return nil, utils.WrapError("Failed to fetch StrategyManager address", err)
}
contractSlasher, err = slasher.NewContractISlasher(slasherAddr, client)
contractStrategyManager, err = strategymanager.NewContractStrategyManager(strategyManagerAddr, client)
if err != nil {
return nil, utils.WrapError("Failed to fetch Slasher contract", err)
return nil, utils.WrapError("Failed to fetch StrategyManager contract", err)
}

strategyManagerAddr, err = contractDelegationManager.StrategyManager(&bind.CallOpts{})
allocationManagerAddr, err = contractDelegationManager.AllocationManager(&bind.CallOpts{})
if err != nil {
return nil, utils.WrapError("Failed to fetch StrategyManager address", err)
return nil, utils.WrapError("Failed to fetch AllocationManager address", err)
}
contractStrategyManager, err = strategymanager.NewContractStrategyManager(strategyManagerAddr, client)
contractAllocationManager, err = allocationmanager.NewContractAllocationManager(allocationManagerAddr, client)
if err != nil {
return nil, utils.WrapError("Failed to fetch StrategyManager contract", err)
return nil, utils.WrapError("Failed to fetch AllocationManager contract", err)
}
}

if isZeroAddress(cfg.AvsDirectoryAddress) {
logger.Debug("AVSDirectory address not provided, the calls to the contract will not work")
} else {
avsDirectory, err = avsdirectory.NewContractIAVSDirectory(cfg.AvsDirectoryAddress, client)
avsDirectory, err = avsdirectory.NewContractAVSDirectory(cfg.AvsDirectoryAddress, client)
if err != nil {
return nil, utils.WrapError("Failed to fetch AVSDirectory contract", err)
}
Expand All @@ -96,16 +96,16 @@ func NewBindingsFromConfig(
}

return &ContractBindings{
SlasherAddr: slasherAddr,
StrategyManagerAddr: strategyManagerAddr,
DelegationManagerAddr: cfg.DelegationManagerAddress,
AvsDirectoryAddr: cfg.AvsDirectoryAddress,
RewardsCoordinatorAddress: cfg.RewardsCoordinatorAddress,
Slasher: contractSlasher,
StrategyManager: contractStrategyManager,
DelegationManager: contractDelegationManager,
AvsDirectory: avsDirectory,
RewardsCoordinator: rewardsCoordinator,
AllocationManager: contractAllocationManager,
AllocationManagerAddr: allocationManagerAddr,
}, nil
}
func isZeroAddress(address gethcommon.Address) bool {
Expand All @@ -125,15 +125,6 @@ func NewEigenlayerContractBindings(
return nil, utils.WrapError("Failed to create DelegationManager contract", err)
}

slasherAddr, err := contractDelegationManager.Slasher(&bind.CallOpts{})
if err != nil {
return nil, utils.WrapError("Failed to fetch Slasher address", err)
}
contractSlasher, err := slasher.NewContractISlasher(slasherAddr, ethclient)
if err != nil {
return nil, utils.WrapError("Failed to fetch Slasher contract", err)
}

strategyManagerAddr, err := contractDelegationManager.StrategyManager(&bind.CallOpts{})
if err != nil {
return nil, utils.WrapError("Failed to fetch StrategyManager address", err)
Expand All @@ -143,17 +134,15 @@ func NewEigenlayerContractBindings(
return nil, utils.WrapError("Failed to fetch StrategyManager contract", err)
}

avsDirectory, err := avsdirectory.NewContractIAVSDirectory(avsDirectoryAddr, ethclient)
avsDirectory, err := avsdirectory.NewContractAVSDirectory(avsDirectoryAddr, ethclient)
if err != nil {
return nil, utils.WrapError("Failed to fetch AVSDirectory contract", err)
}

return &ContractBindings{
SlasherAddr: slasherAddr,
StrategyManagerAddr: strategyManagerAddr,
DelegationManagerAddr: delegationManagerAddr,
AvsDirectoryAddr: avsDirectoryAddr,
Slasher: contractSlasher,
StrategyManager: contractStrategyManager,
DelegationManager: contractDelegationManager,
AvsDirectory: avsDirectory,
Expand Down
6 changes: 3 additions & 3 deletions chainio/clients/elcontracts/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ func BuildReadClients(
}

elChainReader := NewChainReader(
elContractBindings.Slasher,
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.AvsDirectory,
elContractBindings.RewardsCoordinator,
elContractBindings.AllocationManager,
logger,
client,
)
Expand All @@ -54,21 +54,21 @@ func BuildClients(
}

elChainReader := NewChainReader(
elContractBindings.Slasher,
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.AvsDirectory,
elContractBindings.RewardsCoordinator,
elContractBindings.AllocationManager,
logger,
client,
)

elChainWriter := NewChainWriter(
elContractBindings.Slasher,
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.RewardsCoordinator,
elContractBindings.AvsDirectory,
elContractBindings.AllocationManager,
elContractBindings.StrategyManagerAddr,
elChainReader,
client,
Expand Down
Loading

0 comments on commit 985fa2f

Please sign in to comment.