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

updated economic metrics to reflect new spec #19

Merged
merged 3 commits into from
Oct 6, 2023
Merged
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
48 changes: 47 additions & 1 deletion chainio/avsregistry/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package avsregistry

import (
"context"
"math"

"github.com/Layr-Labs/eigensdk-go/chainio/clients"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
blsoperatorstateretrievar "github.com/Layr-Labs/eigensdk-go/contracts/bindings/BLSOperatorStateRetriever"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/types"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethcommon "github.com/ethereum/go-ethereum/common"
)
Expand All @@ -18,6 +20,17 @@ type AvsRegistryReader interface {
blockNumber uint32,
) ([][]blsoperatorstateretrievar.BLSOperatorStateRetrieverOperator, error)

GetOperatorsStakeInQuorumsOfOperatorAtBlock(
ctx context.Context,
operatorId types.OperatorId,
blockNumber uint32,
) ([]types.QuorumNum, [][]blsoperatorstateretrievar.BLSOperatorStateRetrieverOperator, error)

GetOperatorsStakeInQuorumsOfOperatorAtCurrentBlock(
ctx context.Context,
operatorId types.OperatorId,
) ([]types.QuorumNum, [][]blsoperatorstateretrievar.BLSOperatorStateRetrieverOperator, error)

GetCheckSignaturesIndices(
ctx context.Context,
referenceBlockNumber uint32,
Expand Down Expand Up @@ -61,13 +74,46 @@ func (r *AvsRegistryChainReader) GetOperatorsStakeInQuorumsAtBlock(
quorumNumbers,
blockNumber)
if err != nil {
r.logger.Error("Failed to get operator state", "err", err)
r.logger.Error("Failed to get operators state", "err", err)
return nil, err
}

return operatorStakes, nil
}

func (r *AvsRegistryChainReader) GetOperatorsStakeInQuorumsOfOperatorAtBlock(
ctx context.Context,
operatorId types.OperatorId,
blockNumber uint32,
) ([]types.QuorumNum, [][]blsoperatorstateretrievar.BLSOperatorStateRetrieverOperator, error) {
quorums, operatorStakes, err := r.avsRegistryContractsClient.GetOperatorsStakeInQuorumsOfOperatorAtBlock(
&bind.CallOpts{},
operatorId,
blockNumber)
if err != nil {
r.logger.Error("Failed to get operators state", "err", err)
return nil, nil, err
}

return quorums, operatorStakes, nil
}

func (r *AvsRegistryChainReader) GetOperatorsStakeInQuorumsOfOperatorAtCurrentBlock(
ctx context.Context,
operatorId types.OperatorId,
) ([]types.QuorumNum, [][]blsoperatorstateretrievar.BLSOperatorStateRetrieverOperator, error) {
curBlock, err := r.ethClient.BlockNumber(ctx)
if err != nil {
r.logger.Error("Failed to get current block number", "err", err)
return nil, nil, err
}
if curBlock > math.MaxUint32 {
r.logger.Error("Current block number is too large to be converted to uint32")
return nil, nil, err
}
return r.GetOperatorsStakeInQuorumsOfOperatorAtBlock(ctx, operatorId, uint32(curBlock))
}

func (r *AvsRegistryChainReader) GetCheckSignaturesIndices(
ctx context.Context,
referenceBlockNumber uint32,
Expand Down
48 changes: 36 additions & 12 deletions chainio/clients/avs_registry_contracts_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
blspubkeyregistry "github.com/Layr-Labs/eigensdk-go/contracts/bindings/BLSPubkeyRegistry"
regcoord "github.com/Layr-Labs/eigensdk-go/contracts/bindings/BLSRegistryCoordinatorWithIndices"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/types"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethcommon "github.com/ethereum/go-ethereum/common"
Expand All @@ -29,10 +30,16 @@ type AVSRegistryContractsClient interface {

GetOperatorsStakeInQuorumsAtBlock(
opts *bind.CallOpts,
quorumNumbers []byte,
quorumNumbers []types.QuorumNum,
blockNumber uint32,
) ([][]blsoperatorstateretrievar.BLSOperatorStateRetrieverOperator, error)

GetOperatorsStakeInQuorumsOfOperatorAtBlock(
opts *bind.CallOpts,
operatorId types.OperatorId,
blockNumber uint32,
) ([]types.QuorumNum, [][]blsoperatorstateretrievar.BLSOperatorStateRetrieverOperator, error)

GetCheckSignaturesIndices(
opts *bind.CallOpts,
referenceBlockNumber uint32,
Expand All @@ -55,23 +62,23 @@ type AVSRegistryContractsClient interface {
) (*gethTypes.Transaction, error)
}

type AvsregistryContractsChainClient struct {
type AvsRegistryContractsChainClient struct {
avsRegistryBindings *avsRegistryContractBindings
ethHttpClient eth.EthClient
registryCoordinatorAddr gethcommon.Address
logger logging.Logger
}

var _ AVSRegistryContractsClient = (*AvsregistryContractsChainClient)(nil)
var _ AVSRegistryContractsClient = (*AvsRegistryContractsChainClient)(nil)

func NewAVSContractsChainClient(
func NewAvsRegistryContractsChainClient(
blsRegistryCoordinatorAddr gethcommon.Address,
blsOperatorStateRetrieverAddr gethcommon.Address,
stakeregistryAddr gethcommon.Address,
blsPubkeyRegistryAddr gethcommon.Address,
ethClient eth.EthClient,
logger logging.Logger,
) (*AvsregistryContractsChainClient, error) {
) (*AvsRegistryContractsChainClient, error) {
avsRegistryBindings, err := newAVSRegistryContractBindings(
blsRegistryCoordinatorAddr,
blsOperatorStateRetrieverAddr,
Expand All @@ -83,7 +90,7 @@ func NewAVSContractsChainClient(
return nil, err
}

return &AvsregistryContractsChainClient{
return &AvsRegistryContractsChainClient{
avsRegistryBindings: avsRegistryBindings,
ethHttpClient: ethClient,
registryCoordinatorAddr: blsRegistryCoordinatorAddr,
Expand All @@ -92,7 +99,7 @@ func NewAVSContractsChainClient(
}

// Registration specific functions
func (a *AvsregistryContractsChainClient) RegisterOperatorWithCoordinator(
func (a *AvsRegistryContractsChainClient) RegisterOperatorWithCoordinator(
opts *bind.TransactOpts,
quorumNumbers []byte,
pubkey regcoord.BN254G1Point,
Expand All @@ -106,14 +113,14 @@ func (a *AvsregistryContractsChainClient) RegisterOperatorWithCoordinator(
)
}

func (a *AvsregistryContractsChainClient) GetOperatorId(
func (a *AvsRegistryContractsChainClient) GetOperatorId(
opts *bind.CallOpts,
operatorAddress gethcommon.Address,
) ([32]byte, error) {
return a.avsRegistryBindings.RegistryCoordinator.GetOperatorId(opts, operatorAddress)
}

func (a *AvsregistryContractsChainClient) GetOperatorsStakeInQuorumsAtBlock(
func (a *AvsRegistryContractsChainClient) GetOperatorsStakeInQuorumsAtBlock(
opts *bind.CallOpts,
quorumNumbers []byte,
blockNumber uint32,
Expand All @@ -125,7 +132,24 @@ func (a *AvsregistryContractsChainClient) GetOperatorsStakeInQuorumsAtBlock(
blockNumber)
}

func (a *AvsregistryContractsChainClient) GetCheckSignaturesIndices(
func (a *AvsRegistryContractsChainClient) GetOperatorsStakeInQuorumsOfOperatorAtBlock(
opts *bind.CallOpts,
operatorId types.OperatorId,
blockNumber uint32,
) ([]types.QuorumNum, [][]blsoperatorstateretrievar.BLSOperatorStateRetrieverOperator, error) {
quorumBitmap, blsOperatorStateRetrieverOperator, err := a.avsRegistryBindings.BlsOperatorStateRetriever.GetOperatorState0(
opts,
a.registryCoordinatorAddr,
operatorId,
blockNumber)
if err != nil {
return nil, nil, err
}
quorums := types.BitmapToQuorumIds(quorumBitmap)
return quorums, blsOperatorStateRetrieverOperator, nil
}

func (a *AvsRegistryContractsChainClient) GetCheckSignaturesIndices(
opts *bind.CallOpts,
referenceBlockNumber uint32,
quorumNumbers []byte,
Expand All @@ -139,7 +163,7 @@ func (a *AvsregistryContractsChainClient) GetCheckSignaturesIndices(
nonSignerOperatorIds)
}

func (a *AvsregistryContractsChainClient) UpdateStakes(
func (a *AvsRegistryContractsChainClient) UpdateStakes(
opts *bind.TransactOpts,
operators []gethcommon.Address,
operatorIds [][32]byte,
Expand All @@ -152,7 +176,7 @@ func (a *AvsregistryContractsChainClient) UpdateStakes(
prevElements)
}

func (a *AvsregistryContractsChainClient) DeregisterOperator(
func (a *AvsRegistryContractsChainClient) DeregisterOperator(
opts *bind.TransactOpts,
operator gethcommon.Address,
quorumNumbers []byte,
Expand Down
2 changes: 1 addition & 1 deletion chainio/constructor/constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (config *Config) buildAvsRegistryContractsChainClient(
return nil, err
}

avsregistryContractsChainClient, err := clients.NewAVSContractsChainClient(
avsregistryContractsChainClient, err := clients.NewAvsRegistryContractsChainClient(
blsRegistryCoordinatorAddr,
gethcommon.HexToAddress(config.BlsOperatorStateRetrieverAddr),
stakeregistryAddr,
Expand Down
16 changes: 16 additions & 0 deletions chainio/mocks/avsRegistryContractClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions chainio/mocks/avsRegistryContractsReader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading