Skip to content

Commit

Permalink
feat: slashing (Layr-Labs#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur authored Jan 3, 2025
1 parent 2c554f1 commit fce9e63
Show file tree
Hide file tree
Showing 56 changed files with 12,950 additions and 5,087 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 PermissionController"
core_location := "./lib/eigenlayer-middleware/lib/eigenlayer-contracts"
core_bindings_location := "../../../../bindings"

Expand Down
7 changes: 7 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,10 @@ 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)
}
}

if isZeroAddress(cfg.OperatorStateRetrieverAddress) {
Expand All @@ -233,6 +239,7 @@ func NewBindingsFromConfig(
OperatorStateRetrieverAddr: cfg.OperatorStateRetrieverAddress,
DelegationManagerAddr: delegationManagerAddr,
AvsDirectoryAddr: avsDirectoryAddr,
AllocationManagerAddr: allocationManagerAddr,
ServiceManager: contractServiceManager,
RegistryCoordinator: contractBlsRegistryCoordinator,
StakeRegistry: contractStakeRegistry,
Expand Down
32 changes: 31 additions & 1 deletion chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,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
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
67 changes: 36 additions & 31 deletions chainio/clients/elcontracts/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
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"
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 +22,17 @@ 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
PermissionController *permissioncontroller.ContractPermissionController
}

func NewBindingsFromConfig(
Expand All @@ -42,12 +44,13 @@ 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
permissionController *permissioncontroller.ContractPermissionController
)

if isZeroAddress(cfg.DelegationManagerAddress) {
Expand All @@ -58,29 +61,41 @@ 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.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.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 +111,17 @@ 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,
PermissionController: permissionController,
}, nil
}
func isZeroAddress(address gethcommon.Address) bool {
Expand All @@ -125,15 +141,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 +150,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
9 changes: 6 additions & 3 deletions chainio/clients/elcontracts/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ func BuildReadClients(
}

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

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

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

0 comments on commit fce9e63

Please sign in to comment.