Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package avsregistry
package avsblsregistry

import (
"bytes"
Expand Down Expand Up @@ -44,18 +44,18 @@ type AvsRegistryReader interface {

GetOperatorsStakeInQuorumsOfOperatorAtBlock(
opts *bind.CallOpts,
operatorId types.OperatorId,
operatorId types.BlsOperatorId,
blockNumber uint32,
) ([]types.QuorumNum, [][]opstateretriever.OperatorStateRetrieverOperator, error)

GetOperatorsStakeInQuorumsOfOperatorAtCurrentBlock(
opts *bind.CallOpts,
operatorId types.OperatorId,
operatorId types.BlsOperatorId,
) ([]types.QuorumNum, [][]opstateretriever.OperatorStateRetrieverOperator, error)

GetOperatorStakeInQuorumsOfOperatorAtCurrentBlock(
opts *bind.CallOpts,
operatorId types.OperatorId,
operatorId types.BlsOperatorId,
) (map[types.QuorumNum]types.StakeAmount, error)

GetCheckSignaturesIndices(
Expand All @@ -67,7 +67,7 @@ type AvsRegistryReader interface {

GetOperatorId(opts *bind.CallOpts, operatorAddress gethcommon.Address) ([32]byte, error)

GetOperatorFromId(opts *bind.CallOpts, operatorId types.OperatorId) (gethcommon.Address, error)
GetOperatorFromId(opts *bind.CallOpts, operatorId types.BlsOperatorId) (gethcommon.Address, error)

IsOperatorRegistered(opts *bind.CallOpts, operatorAddress gethcommon.Address) (bool, error)

Expand Down Expand Up @@ -233,7 +233,7 @@ func (r *AvsRegistryChainReader) GetOperatorAddrsInQuorumsAtCurrentBlock(

func (r *AvsRegistryChainReader) GetOperatorsStakeInQuorumsOfOperatorAtBlock(
opts *bind.CallOpts,
operatorId types.OperatorId,
operatorId types.BlsOperatorId,
blockNumber uint32,
) ([]types.QuorumNum, [][]opstateretriever.OperatorStateRetrieverOperator, error) {
quorumBitmap, operatorStakes, err := r.operatorStateRetriever.GetOperatorState0(
Expand All @@ -259,7 +259,7 @@ func (r *AvsRegistryChainReader) GetOperatorsStakeInQuorumsOfOperatorAtBlock(
// blockNumber in opts will be ignored, and the chain will be queried to get the latest blockNumber
func (r *AvsRegistryChainReader) GetOperatorsStakeInQuorumsOfOperatorAtCurrentBlock(
opts *bind.CallOpts,
operatorId types.OperatorId,
operatorId types.BlsOperatorId,
) ([]types.QuorumNum, [][]opstateretriever.OperatorStateRetrieverOperator, error) {
if opts.Context == nil {
opts.Context = context.Background()
Expand All @@ -282,7 +282,7 @@ func (r *AvsRegistryChainReader) GetOperatorsStakeInQuorumsOfOperatorAtCurrentBl
// so some of them could actually return information from different blocks
func (r *AvsRegistryChainReader) GetOperatorStakeInQuorumsOfOperatorAtCurrentBlock(
opts *bind.CallOpts,
operatorId types.OperatorId,
operatorId types.BlsOperatorId,
) (map[types.QuorumNum]types.StakeAmount, error) {
quorumBitmap, err := r.registryCoordinator.GetCurrentQuorumBitmap(opts, operatorId)
if err != nil {
Expand Down Expand Up @@ -343,7 +343,7 @@ func (r *AvsRegistryChainReader) GetOperatorId(

func (r *AvsRegistryChainReader) GetOperatorFromId(
opts *bind.CallOpts,
operatorId types.OperatorId,
operatorId types.BlsOperatorId,
) (gethcommon.Address, error) {
operatorAddress, err := r.registryCoordinator.GetOperatorFromId(
opts,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package avsregistry
package avsblsregistry

import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package avsregistry
package avsblsregistry

import (
"context"
Expand Down
141 changes: 141 additions & 0 deletions chainio/clients/avsregistry/ecdsa/reader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package avsecdsaregistry

import (
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethcommon "github.com/ethereum/go-ethereum/common"

opstateretriever "github.com/Layr-Labs/eigensdk-go/contracts/bindings/ECDSAOperatorStateRetriever"
regcoord "github.com/Layr-Labs/eigensdk-go/contracts/bindings/ECDSARegistryCoordinator"
)

type AvsEcdsaRegistryReader interface {
GetOperatorsStakeInQuorumsAtBlock(
opts *bind.CallOpts,
quorumNumbers []byte,
blockNumber uint32,
) ([][]opstateretriever.ECDSAOperatorStateRetrieverOperator, error)

GetCheckSignaturesIndices(
opts *bind.CallOpts,
referenceBlockNumber uint32,
quorumNumbers []byte,
nonSignerOperatorIds []gethcommon.Address,
) (opstateretriever.ECDSAOperatorStateRetrieverCheckSignaturesIndices, error)

IsOperatorRegistered(
opts *bind.CallOpts,
operatorAddress gethcommon.Address,
) (bool, error)
}

type AvsEcdsaRegistryChainReader struct {
logger logging.Logger
registryCoordinatorAddr gethcommon.Address
registryCoordinator *regcoord.ContractECDSARegistryCoordinator
operatorStateRetriever *opstateretriever.ContractECDSAOperatorStateRetriever
ethClient eth.EthClient
}

// forces AvsReader to implement the clients.ReaderInterface interface
var _ AvsEcdsaRegistryReader = (*AvsEcdsaRegistryChainReader)(nil)

func NewAvsEcdsaRegistryChainReader(
registryCoordinatorAddr gethcommon.Address,
registerCoordinator *regcoord.ContractECDSARegistryCoordinator,
operatorStateRetriever *opstateretriever.ContractECDSAOperatorStateRetriever,
logger logging.Logger,
ethClient eth.EthClient,
) *AvsEcdsaRegistryChainReader {
return &AvsEcdsaRegistryChainReader{
registryCoordinatorAddr: registryCoordinatorAddr,
registryCoordinator: registerCoordinator,
operatorStateRetriever: operatorStateRetriever,
logger: logger,
ethClient: ethClient,
}
}

func BuildAvsEcdsaRegistryChainReader(
registryCoordinatorAddr gethcommon.Address,
operatorStateRetrieverAddr gethcommon.Address,
ethClient eth.EthClient,
logger logging.Logger,
) (*AvsEcdsaRegistryChainReader, error) {
contractOperatorStateRetriever, err := opstateretriever.NewContractECDSAOperatorStateRetriever(
operatorStateRetrieverAddr,
ethClient,
)
if err != nil {
return nil, err
}
contractRegistryCoordinator, err := regcoord.NewContractECDSARegistryCoordinator(
registryCoordinatorAddr,
ethClient,
)
if err != nil {
return nil, err
}
return NewAvsEcdsaRegistryChainReader(
registryCoordinatorAddr,
contractRegistryCoordinator,
contractOperatorStateRetriever,
logger,
ethClient,
), nil
}

func (r *AvsEcdsaRegistryChainReader) GetCheckSignaturesIndices(
opts *bind.CallOpts,
referenceBlockNumber uint32,
quorumNumbers []byte,
signerOperatorIds []gethcommon.Address,
) (opstateretriever.ECDSAOperatorStateRetrieverCheckSignaturesIndices, error) {
checkSignatureIndices, err := r.operatorStateRetriever.GetCheckSignaturesIndices(
opts,
r.registryCoordinatorAddr,
referenceBlockNumber,
quorumNumbers,
signerOperatorIds,
)
if err != nil {
r.logger.Error("Failed to get check signatures indices", "err", err)
return opstateretriever.ECDSAOperatorStateRetrieverCheckSignaturesIndices{}, err
}
return checkSignatureIndices, nil
}

// the contract stores historical state, so blockNumber should be the block number of the state you want to query
// and the blockNumber in opts should be the block number of the latest block (or set to nil, which is equivalent)
func (r *AvsEcdsaRegistryChainReader) GetOperatorsStakeInQuorumsAtBlock(
opts *bind.CallOpts,
quorumNumbers []byte,
blockNumber uint32,
) ([][]opstateretriever.ECDSAOperatorStateRetrieverOperator, error) {
operatorStakes, err := r.operatorStateRetriever.GetOperatorState0(
opts,
r.registryCoordinatorAddr,
quorumNumbers,
blockNumber)
if err != nil {
r.logger.Error("Failed to get operators state", "err", err)
return nil, err
}
return operatorStakes, nil
}

func (r *AvsEcdsaRegistryChainReader) IsOperatorRegistered(
opts *bind.CallOpts,
operatorAddress gethcommon.Address,
) (bool, error) {
operatorStatus, err := r.registryCoordinator.GetOperatorStatus(opts, operatorAddress)
if err != nil {
r.logger.Error("Cannot get operator status", "err", err)
return false, err
}

// 0 = NEVER_REGISTERED, 1 = REGISTERED, 2 = DEREGISTERED
registeredWithAvs := operatorStatus == 1
return registeredWithAvs, nil
}
Loading