Skip to content

Commit

Permalink
docs: avsregistry/reader (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricomateo authored Jan 31, 2025
1 parent 0b15fc3 commit d5a1b93
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion chainio/clients/avsregistry/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type Config struct {
OperatorStateRetrieverAddress common.Address
}

// The ChainReader provides methods to call the
// AVS registry contract's view functions.
type ChainReader struct {
logger logging.Logger
blsApkRegistryAddr common.Address
Expand All @@ -40,6 +42,7 @@ type ChainReader struct {
ethClient eth.HttpBackend
}

// Creates a new instance of the ChainReader.
func NewChainReader(
registryCoordinatorAddr common.Address,
blsApkRegistryAddr common.Address,
Expand Down Expand Up @@ -84,13 +87,16 @@ func NewReaderFromConfig(
), nil
}

// Returns the total quorum count read from the RegistryCoordinator
func (r *ChainReader) GetQuorumCount(opts *bind.CallOpts) (uint8, error) {
if r.registryCoordinator == nil {
return 0, errors.New("RegistryCoordinator contract not provided")
}
return r.registryCoordinator.QuorumCount(opts)
}

// Returns, for each quorum in `quorumNumbers`, a vector of the operators registered for
// that quorum at the current block, containing each operator's `operatorId` and `stake`.
func (r *ChainReader) GetOperatorsStakeInQuorumsAtCurrentBlock(
opts *bind.CallOpts,
quorumNumbers types.QuorumNums,
Expand Down Expand Up @@ -130,14 +136,15 @@ func (r *ChainReader) GetOperatorsStakeInQuorumsAtBlock(
return operatorStakes, nil
}

// Returns, for each quorum in `quorumNumbers`, a vector of the addresses of the
// operators registered for that quorum at the current block.
func (r *ChainReader) GetOperatorAddrsInQuorumsAtCurrentBlock(
opts *bind.CallOpts,
quorumNumbers types.QuorumNums,
) ([][]common.Address, error) {
if r.operatorStateRetriever == nil {
return nil, errors.New("OperatorStateRetriever contract not provided")
}

if opts.Context == nil {
opts.Context = context.Background()
}
Expand Down Expand Up @@ -169,6 +176,10 @@ func (r *ChainReader) GetOperatorAddrsInQuorumsAtCurrentBlock(

}

// Returns a tuple containing
// - An array with the quorum IDs in which the given operator is registered at the given block
// - An array that contains, for each quorum, an array with the address, id and stake
// of each operator registered in that quorum.
func (r *ChainReader) GetOperatorsStakeInQuorumsOfOperatorAtBlock(
opts *bind.CallOpts,
operatorId types.OperatorId,
Expand Down Expand Up @@ -261,6 +272,8 @@ func (r *ChainReader) GetOperatorStakeInQuorumsOfOperatorAtCurrentBlock(
return quorumStakes, nil
}

// Returns a struct containing the indices of the quorum members that signed,
// and the ones that didn't.
func (r *ChainReader) GetCheckSignaturesIndices(
opts *bind.CallOpts,
referenceBlockNumber uint32,
Expand Down Expand Up @@ -293,6 +306,7 @@ func (r *ChainReader) GetCheckSignaturesIndices(
return checkSignatureIndices, nil
}

// Given an operator address, returns its ID.
func (r *ChainReader) GetOperatorId(
opts *bind.CallOpts,
operatorAddress common.Address,
Expand All @@ -311,6 +325,7 @@ func (r *ChainReader) GetOperatorId(
return operatorId, nil
}

// Given an operator ID, returns its address.
func (r *ChainReader) GetOperatorFromId(
opts *bind.CallOpts,
operatorId types.OperatorId,
Expand All @@ -329,6 +344,8 @@ func (r *ChainReader) GetOperatorFromId(
return operatorAddress, nil
}

// Returns an array of booleans, where the boolean at index i represents
// whether the operator is registered for the quorum i.
func (r *ChainReader) QueryRegistrationDetail(
opts *bind.CallOpts,
operatorAddress common.Address,
Expand Down Expand Up @@ -358,6 +375,7 @@ func (r *ChainReader) QueryRegistrationDetail(
return quorums, nil
}

// Returns true if the operator is registered, false otherwise.
func (r *ChainReader) IsOperatorRegistered(
opts *bind.CallOpts,
operatorAddress common.Address,
Expand All @@ -376,6 +394,9 @@ func (r *ChainReader) IsOperatorRegistered(
return registeredWithAvs, nil
}

// Queries existing operators for a particular block range.
// Returns two arrays. The first one contains the addresses
// of the operators, and the second contains their corresponding public keys.
func (r *ChainReader) QueryExistingRegisteredOperatorPubKeys(
ctx context.Context,
startBlock *big.Int,
Expand Down Expand Up @@ -475,6 +496,9 @@ func (r *ChainReader) QueryExistingRegisteredOperatorPubKeys(
return operatorAddresses, operatorPubkeys, nil
}

// Queries existing operator sockets for a particular block range.
// Returns a mapping containing operator IDs as keys and their
// corresponding sockets as values.
func (r *ChainReader) QueryExistingRegisteredOperatorSockets(
ctx context.Context,
startBlock *big.Int,
Expand Down

0 comments on commit d5a1b93

Please sign in to comment.