Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Update sdk to new contract layout with slashing feature branch #415

Draft
wants to merge 14 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "contracts/lib/eigenlayer-middleware"]
path = contracts/lib/eigenlayer-middleware
url = git@github.com:Layr-Labs/eigenlayer-middleware.git
url = https://github.com/Layr-Labs/eigenlayer-middleware
[submodule "contracts/lib/forge-std"]
path = contracts/lib/forge-std
url = [email protected]:foundry-rs/forge-std
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 AllocationManager EigenPod EigenPodManager IStrategy IAVSDirectory"
core_location := "./lib/eigenlayer-middleware/lib/eigenlayer-contracts"
core_bindings_location := "../../../../bindings"

Expand Down
8 changes: 8 additions & 0 deletions chainio/clients/avsregistry/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ContractBindings struct {
IndexRegistryAddr gethcommon.Address
DelegationManagerAddr gethcommon.Address
AvsDirectoryAddr gethcommon.Address
AllocationManagerAddr gethcommon.Address
// contract bindings
ServiceManager *servicemanager.ContractServiceManagerBase
RegistryCoordinator *regcoordinator.ContractRegistryCoordinator
Expand Down Expand Up @@ -136,6 +137,7 @@ func NewBindingsFromConfig(
indexRegistryAddr gethcommon.Address
delegationManagerAddr gethcommon.Address
avsDirectoryAddr gethcommon.Address
allocationManagerAddr gethcommon.Address

contractBlsRegistryCoordinator *regcoordinator.ContractRegistryCoordinator
contractServiceManager *servicemanager.ContractServiceManagerBase
Expand Down Expand Up @@ -209,6 +211,11 @@ func NewBindingsFromConfig(
if err != nil {
return nil, utils.WrapError("Failed to get AvsDirectory address", err)
}
allocationManagerAddr, err = contractServiceManager.AllocationManager(&bind.CallOpts{})
if err != nil {
return nil, utils.WrapError("Failed to get AllocationManager address", err)
}

}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we could add the same idea of the check as in elcontracts:

if isZeroAddress(cfg.AllocationManagerAddress) {
...

if we don't get the address of the allocation Manager, we should ignore it while creating the return of the function.

if isZeroAddress(cfg.OperatorStateRetrieverAddress) {
Expand All @@ -232,6 +239,7 @@ func NewBindingsFromConfig(
IndexRegistryAddr: indexRegistryAddr,
OperatorStateRetrieverAddr: cfg.OperatorStateRetrieverAddress,
DelegationManagerAddr: delegationManagerAddr,
AllocationManagerAddr: allocationManagerAddr,
AvsDirectoryAddr: avsDirectoryAddr,
ServiceManager: contractServiceManager,
RegistryCoordinator: contractBlsRegistryCoordinator,
Expand Down
1 change: 1 addition & 0 deletions chainio/clients/avsregistry/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func BuildClients(
elcontracts.Config{
DelegationManagerAddress: avsBindings.DelegationManagerAddr,
AvsDirectoryAddress: avsBindings.AvsDirectoryAddr,
AllocationManagerAddress: avsBindings.AllocationManagerAddr,
},
client,
logger,
Expand Down
45 changes: 43 additions & 2 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,17 @@ func BuildAvsRegistryChainWriter(
if err != nil {
return nil, utils.WrapError("Failed to get AvsDirectory address", err)
}
elReader, err := elcontracts.BuildELChainReader(delegationManagerAddr, avsDirectoryAddr, ethClient, logger)
allocationManagerAddr, err := serviceManager.AllocationManager(&bind.CallOpts{})
if err != nil {
return nil, utils.WrapError("Failed to get AllocationManager address", err)
}
elReader, err := elcontracts.BuildELChainReader(
delegationManagerAddr,
avsDirectoryAddr,
allocationManagerAddr,
ethClient,
logger,
)
if err != nil {
return nil, utils.WrapError("Failed to create ELChainReader", err)
}
Expand Down Expand Up @@ -158,6 +168,7 @@ func NewWriterFromConfig(
elReader, err := elcontracts.NewReaderFromConfig(elcontracts.Config{
DelegationManagerAddress: bindings.DelegationManagerAddr,
AvsDirectoryAddress: bindings.AvsDirectoryAddr,
AllocationManagerAddress: bindings.AllocationManagerAddr,
}, client, logger)
if err != nil {
return nil, err
Expand Down Expand Up @@ -490,7 +501,37 @@ func (w *ChainWriter) DeregisterOperator(
if err != nil {
return nil, err
}
tx, err := w.registryCoordinator.DeregisterOperator(noSendTxOpts, quorumNumbers.UnderlyingType())
tx, err := w.registryCoordinator.DeregisterOperator0(noSendTxOpts, quorumNumbers.UnderlyingType())
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, errors.New("failed to send tx with err: " + err.Error())
}
w.logger.Info(
"successfully deregistered operator with the AVS's registry coordinator",
"txHash",
receipt.TxHash.String(),
)
return receipt, nil
}

func (w *ChainWriter) DeregisterOperatorOperatorSets(
ctx context.Context,
operatorSetIds types.OperatorSetIds,
operator types.Operator,
pubkey regcoord.BN254G1Point,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
w.logger.Info("deregistering operator with the AVS's registry coordinator")

operatorAddress := gethcommon.HexToAddress(operator.Address)
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, err
}
tx, err := w.registryCoordinator.DeregisterOperator(noSendTxOpts, operatorAddress, operatorSetIds.UnderlyingType())
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions chainio/clients/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func BuildReadClients(
elcontracts.Config{
DelegationManagerAddress: avsRegistryContractBindings.DelegationManagerAddr,
AvsDirectoryAddress: avsRegistryContractBindings.AvsDirectoryAddr,
AllocationManagerAddress: avsRegistryContractBindings.AllocationManagerAddr,
},
ethHttpClient,
logger,
Expand Down Expand Up @@ -181,6 +182,7 @@ func BuildAll(
elcontracts.Config{
DelegationManagerAddress: avsRegistryContractBindings.DelegationManagerAddr,
AvsDirectoryAddress: avsRegistryContractBindings.AvsDirectoryAddr,
AllocationManagerAddress: avsRegistryContractBindings.AllocationManagerAddr,
},
ethHttpClient,
txMgr,
Expand Down
55 changes: 28 additions & 27 deletions chainio/clients/eigenpod/bindings/IEigenPod.go

Large diffs are not rendered by default.

440 changes: 210 additions & 230 deletions chainio/clients/eigenpod/bindings/IEigenPodManager.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion chainio/clients/eigenpod/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cleanup_bindings_dir() {

clone() {
echo "Cloning the EigenLayer contracts repository"
git clone -b feat/partial-withdrawal-batching --depth=1 [email protected]:Layr-Labs/eigenlayer-contracts.git "${TMP_DIR}"
git clone -b slashing-magnitudes --depth=1 [email protected]:Layr-Labs/eigenlayer-contracts.git "${TMP_DIR}"
}

generate_bindings() {
Expand Down
50 changes: 23 additions & 27 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"
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,15 +21,15 @@ 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
AllocationManagerAddr gethcommon.Address
RewardsCoordinatorAddress gethcommon.Address
Slasher *slasher.ContractISlasher
DelegationManager *delegationmanager.ContractDelegationManager
StrategyManager *strategymanager.ContractStrategyManager
AvsDirectory *avsdirectory.ContractIAVSDirectory
AllocationManager *allocationmanager.ContractAllocationManager
RewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
}

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

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

Expand All @@ -58,15 +57,6 @@ func NewBindingsFromConfig(
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, client)
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 @@ -86,6 +76,15 @@ func NewBindingsFromConfig(
}
}

if isZeroAddress(cfg.AllocationManagerAddress) {
logger.Debug("AllocationManager address not provided, the calls made to the contract will not work")
} else {
allocationManager, err = allocationmanager.NewContractAllocationManager(cfg.AllocationManagerAddress, client)
if err != nil {
return nil, utils.WrapError("Failed to fetch AllocationManager contract", err)
}
}

if isZeroAddress(cfg.RewardsCoordinatorAddress) {
logger.Debug("RewardsCoordinator address not provided, the calls to the contract will not work")
} else {
Expand All @@ -96,15 +95,15 @@ func NewBindingsFromConfig(
}

return &ContractBindings{
SlasherAddr: slasherAddr,
StrategyManagerAddr: strategyManagerAddr,
DelegationManagerAddr: cfg.DelegationManagerAddress,
AvsDirectoryAddr: cfg.AvsDirectoryAddress,
AllocationManagerAddr: cfg.AllocationManagerAddress,
RewardsCoordinatorAddress: cfg.RewardsCoordinatorAddress,
Slasher: contractSlasher,
StrategyManager: contractStrategyManager,
DelegationManager: contractDelegationManager,
AvsDirectory: avsDirectory,
AllocationManager: allocationManager,
RewardsCoordinator: rewardsCoordinator,
}, nil
}
Expand All @@ -117,6 +116,7 @@ func isZeroAddress(address gethcommon.Address) bool {
func NewEigenlayerContractBindings(
delegationManagerAddr gethcommon.Address,
avsDirectoryAddr gethcommon.Address,
allocationManagerAddr gethcommon.Address,
ethclient eth.HttpBackend,
logger logging.Logger,
) (*ContractBindings, error) {
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 @@ -148,14 +139,19 @@ func NewEigenlayerContractBindings(
return nil, utils.WrapError("Failed to fetch AVSDirectory contract", err)
}

allocationManager, err := allocationmanager.NewContractAllocationManager(allocationManagerAddr, ethclient)
if err != nil {
return nil, utils.WrapError("Failed to fetch AllocationManager contract", err)
}

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

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

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

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