Skip to content

Commit

Permalink
building with Allocation Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
afkbyte committed Dec 23, 2024
1 parent 90a6dca commit 5b7789c
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 29 deletions.
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)
}

}

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
39 changes: 37 additions & 2 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ 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 +162,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 +495,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
11 changes: 11 additions & 0 deletions chainio/clients/elcontracts/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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"
Expand All @@ -23,10 +24,12 @@ type ContractBindings struct {
StrategyManagerAddr gethcommon.Address
DelegationManagerAddr gethcommon.Address
AvsDirectoryAddr gethcommon.Address
AllocationManagerAddr gethcommon.Address
RewardsCoordinatorAddress gethcommon.Address
DelegationManager *delegationmanager.ContractDelegationManager
StrategyManager *strategymanager.ContractStrategyManager
AvsDirectory *avsdirectory.ContractIAVSDirectory
AllocationManager *allocationmanager.ContractAllocationManager
RewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
}

Expand Down Expand Up @@ -101,6 +104,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 @@ -123,12 +127,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{
StrategyManagerAddr: strategyManagerAddr,
DelegationManagerAddr: delegationManagerAddr,
AvsDirectoryAddr: avsDirectoryAddr,
AllocationManagerAddr: allocationManagerAddr,
StrategyManager: contractStrategyManager,
DelegationManager: contractDelegationManager,
AvsDirectory: avsDirectory,
AllocationManager: allocationManager,
}, nil
}
3 changes: 3 additions & 0 deletions chainio/clients/elcontracts/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func BuildReadClients(
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.AvsDirectory,
elContractBindings.AllocationManager,
elContractBindings.RewardsCoordinator,
logger,
client,
Expand Down Expand Up @@ -56,6 +57,7 @@ func BuildClients(
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.AvsDirectory,
elContractBindings.AllocationManager,
elContractBindings.RewardsCoordinator,
logger,
client,
Expand All @@ -66,6 +68,7 @@ func BuildClients(
elContractBindings.StrategyManager,
elContractBindings.RewardsCoordinator,
elContractBindings.AvsDirectory,
elContractBindings.AllocationManager,
elContractBindings.StrategyManagerAddr,
elChainReader,
client,
Expand Down
26 changes: 20 additions & 6 deletions chainio/clients/elcontracts/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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"
erc20 "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IERC20"
Expand All @@ -25,6 +26,7 @@ import (
type Config struct {
DelegationManagerAddress common.Address
AvsDirectoryAddress common.Address
AllocationManagerAddress common.Address
RewardsCoordinatorAddress common.Address
}

Expand All @@ -33,6 +35,7 @@ type ChainReader struct {
delegationManager *delegationmanager.ContractDelegationManager
strategyManager *strategymanager.ContractStrategyManager
avsDirectory *avsdirectory.ContractIAVSDirectory
allocationManager *allocationmanager.ContractAllocationManager
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
ethClient eth.HttpBackend
}
Expand All @@ -41,6 +44,7 @@ func NewChainReader(
delegationManager *delegationmanager.ContractDelegationManager,
strategyManager *strategymanager.ContractStrategyManager,
avsDirectory *avsdirectory.ContractIAVSDirectory,
allocationManager *allocationmanager.ContractAllocationManager,
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator,
logger logging.Logger,
ethClient eth.HttpBackend,
Expand All @@ -51,6 +55,7 @@ func NewChainReader(
delegationManager: delegationManager,
strategyManager: strategyManager,
avsDirectory: avsDirectory,
allocationManager: allocationManager,
rewardsCoordinator: rewardsCoordinator,
logger: logger,
ethClient: ethClient,
Expand All @@ -62,12 +67,14 @@ func NewChainReader(
func BuildELChainReader(
delegationManagerAddr gethcommon.Address,
avsDirectoryAddr gethcommon.Address,
allocationManagerAddr gethcommon.Address,
ethClient eth.HttpBackend,
logger logging.Logger,
) (*ChainReader, error) {
elContractBindings, err := NewEigenlayerContractBindings(
delegationManagerAddr,
avsDirectoryAddr,
allocationManagerAddr,
ethClient,
logger,
)
Expand All @@ -78,6 +85,7 @@ func BuildELChainReader(
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.AvsDirectory,
elContractBindings.AllocationManager,
elContractBindings.RewardsCoordinator,
logger,
ethClient,
Expand All @@ -101,6 +109,7 @@ func NewReaderFromConfig(
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.AvsDirectory,
elContractBindings.AllocationManager,
elContractBindings.RewardsCoordinator,
logger,
ethClient,
Expand Down Expand Up @@ -134,18 +143,23 @@ func (r *ChainReader) GetOperatorDetails(
return types.Operator{}, errors.New("DelegationManager contract not provided")
}

operatorDetails, err := r.delegationManager.OperatorDetails(
delegationApproverAddr, err := r.delegationManager.DelegationApprover(
&bind.CallOpts{Context: ctx},
gethcommon.HexToAddress(operator.Address),
)
if err != nil {
return types.Operator{}, err
}

_, operatorMagnitudeAllocationDelay, err := r.allocationManager.GetAllocationDelay(
&bind.CallOpts{Context: ctx},
gethcommon.HexToAddress(operator.Address),
)

return types.Operator{
Address: operator.Address,
StakerOptOutWindowBlocks: operatorDetails.StakerOptOutWindowBlocks,
DelegationApproverAddress: operatorDetails.DelegationApprover.Hex(),
DelegationApproverAddress: delegationApproverAddr.Hex(),
AllocationDelay: operatorMagnitudeAllocationDelay,
}, nil
}

Expand Down Expand Up @@ -293,9 +307,9 @@ func (r *ChainReader) CurrRewardsCalculationEndTimestamp(ctx context.Context) (u

func (r *ChainReader) GetCurrentClaimableDistributionRoot(
ctx context.Context,
) (rewardscoordinator.IRewardsCoordinatorDistributionRoot, error) {
) (rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot, error) {
if r.rewardsCoordinator == nil {
return rewardscoordinator.IRewardsCoordinatorDistributionRoot{}, errors.New(
return rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot{}, errors.New(
"RewardsCoordinator contract not provided",
)
}
Expand Down Expand Up @@ -328,7 +342,7 @@ func (r *ChainReader) GetCumulativeClaimed(

func (r *ChainReader) CheckClaim(
ctx context.Context,
claim rewardscoordinator.IRewardsCoordinatorRewardsMerkleClaim,
claim rewardscoordinator.IRewardsCoordinatorTypesRewardsMerkleClaim,
) (bool, error) {
if r.rewardsCoordinator == nil {
return false, errors.New("RewardsCoordinator contract not provided")
Expand Down
Loading

0 comments on commit 5b7789c

Please sign in to comment.