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

chore: mock to fake #302

Merged
merged 6 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
66 changes: 0 additions & 66 deletions chainio/clients/avsregistry/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,69 +25,6 @@ import (
// 10k is an arbitrary choice that should work for most
var DefaultQueryBlockRange = big.NewInt(10_000)

type Reader interface {
GetQuorumCount(opts *bind.CallOpts) (uint8, error)

GetOperatorsStakeInQuorumsAtCurrentBlock(
opts *bind.CallOpts,
quorumNumbers types.QuorumNums,
) ([][]opstateretriever.OperatorStateRetrieverOperator, error)

GetOperatorsStakeInQuorumsAtBlock(
opts *bind.CallOpts,
quorumNumbers types.QuorumNums,
blockNumber uint32,
) ([][]opstateretriever.OperatorStateRetrieverOperator, error)

GetOperatorAddrsInQuorumsAtCurrentBlock(
opts *bind.CallOpts,
quorumNumbers types.QuorumNums,
) ([][]common.Address, error)

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

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

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

GetCheckSignaturesIndices(
opts *bind.CallOpts,
referenceBlockNumber uint32,
quorumNumbers types.QuorumNums,
nonSignerOperatorIds []types.OperatorId,
) (opstateretriever.OperatorStateRetrieverCheckSignaturesIndices, error)

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

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

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

QueryExistingRegisteredOperatorPubKeys(
ctx context.Context,
startBlock *big.Int,
stopBlock *big.Int,
blockRange *big.Int,
) ([]types.OperatorAddr, []types.OperatorPubkeys, error)

QueryExistingRegisteredOperatorSockets(
ctx context.Context,
startBlock *big.Int,
stopBlock *big.Int,
blockRange *big.Int,
) (map[types.OperatorId]types.Socket, error)
}

type Config struct {
RegistryCoordinatorAddress common.Address
OperatorStateRetrieverAddress common.Address
Expand All @@ -103,9 +40,6 @@ type ChainReader struct {
ethClient eth.Client
}

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

func NewChainReader(
registryCoordinatorAddr common.Address,
blsApkRegistryAddr common.Address,
Expand Down
8 changes: 0 additions & 8 deletions chainio/clients/avsregistry/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,12 @@ import (
"github.com/Layr-Labs/eigensdk-go/utils"
)

type Subscriber interface {
SubscribeToNewPubkeyRegistrations() (chan *blsapkreg.ContractBLSApkRegistryNewPubkeyRegistration, event.Subscription, error)
SubscribeToOperatorSocketUpdates() (chan *regcoord.ContractRegistryCoordinatorOperatorSocketUpdate, event.Subscription, error)
}

type ChainSubscriber struct {
logger logging.Logger
regCoord regcoord.ContractRegistryCoordinatorFilters
blsApkRegistry blsapkreg.ContractBLSApkRegistryFilters
}

// forces EthSubscriber to implement the chainio.Subscriber interface
var _ Subscriber = (*ChainSubscriber)(nil)

// NewChainSubscriber creates a new instance of ChainSubscriber
// The bindings must be created using websocket ETH Client
func NewChainSubscriber(
Expand Down
88 changes: 22 additions & 66 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,68 +27,7 @@ import (
"github.com/Layr-Labs/eigensdk-go/utils"
)

type Writer interface {

// RegisterOperatorInQuorumWithAVSRegistryCoordinator
// TODO(samlaf): an operator that is already registered in a quorum can register with another quorum without passing
// signatures perhaps we should add another sdk function for this purpose, that just takes in a quorumNumber and
// socket? RegisterOperatorInQuorumWithAVSRegistryCoordinator is used to register a single operator with the AVS's
// registry coordinator. - operatorEcdsaPrivateKey is the operator's ecdsa private key (used to sign a message to
// register operator in eigenlayer's delegation manager)
// - operatorToAvsRegistrationSigSalt is a random salt used to prevent replay attacks
// - operatorToAvsRegistrationSigExpiry is the expiry time of the signature
//
// Deprecated: use RegisterOperator instead.
// We will only keep high-level functionality such as RegisterOperator, and low level functionality
// such as this function should eventually all be done with bindings directly instead.
RegisterOperatorInQuorumWithAVSRegistryCoordinator(
ctx context.Context,
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
operatorToAvsRegistrationSigSalt [32]byte,
operatorToAvsRegistrationSigExpiry *big.Int,
blsKeyPair *bls.KeyPair,
quorumNumbers types.QuorumNums,
socket string,
) (*gethtypes.Receipt, error)

// RegisterOperator is similar to RegisterOperatorInQuorumWithAVSRegistryCoordinator but
// generates a random salt and expiry for the signature.
RegisterOperator(
ctx context.Context,
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
blsKeyPair *bls.KeyPair,
quorumNumbers types.QuorumNums,
socket string,
) (*gethtypes.Receipt, error)

// UpdateStakesOfEntireOperatorSetForQuorums is used by avs teams running https://github.com/Layr-Labs/avs-sync
// to updates the stake of their entire operator set.
// Because of high gas costs of this operation, it typically needs to be called for every quorum, or perhaps for a
// small grouping of quorums
// (highly dependent on number of operators per quorum)
UpdateStakesOfEntireOperatorSetForQuorums(
ctx context.Context,
operatorsPerQuorum [][]gethcommon.Address,
quorumNumbers types.QuorumNums,
) (*gethtypes.Receipt, error)

// UpdateStakesOfOperatorSubsetForAllQuorums is meant to be used by single operators (or teams of operators,
// possibly running https://github.com/Layr-Labs/avs-sync) to update the stake of their own operator(s). This might
// be needed in the case that they received a lot of new stake delegations, and want this to be reflected
// in the AVS's registry coordinator.
UpdateStakesOfOperatorSubsetForAllQuorums(
ctx context.Context,
operators []gethcommon.Address,
) (*gethtypes.Receipt, error)

DeregisterOperator(
ctx context.Context,
quorumNumbers types.QuorumNums,
pubkey regcoord.BN254G1Point,
) (*gethtypes.Receipt, error)
}

type ELReader interface {
type eLReader interface {
CalculateOperatorAVSRegistrationDigestHash(
opts *bind.CallOpts,
operatorAddr gethcommon.Address,
Expand All @@ -104,21 +43,19 @@ type ChainWriter struct {
operatorStateRetriever *opstateretriever.ContractOperatorStateRetriever
stakeRegistry *stakeregistry.ContractStakeRegistry
blsApkRegistry *blsapkregistry.ContractBLSApkRegistry
elReader ELReader
elReader eLReader
logger logging.Logger
ethClient eth.Client
txMgr txmgr.TxManager
}

var _ Writer = (*ChainWriter)(nil)

func NewChainWriter(
serviceManagerAddr gethcommon.Address,
registryCoordinator *regcoord.ContractRegistryCoordinator,
operatorStateRetriever *opstateretriever.ContractOperatorStateRetriever,
stakeRegistry *stakeregistry.ContractStakeRegistry,
blsApkRegistry *blsapkregistry.ContractBLSApkRegistry,
elReader ELReader,
elReader eLReader,
logger logging.Logger,
ethClient eth.Client,
txMgr txmgr.TxManager,
Expand Down Expand Up @@ -239,6 +176,18 @@ func NewWriterFromConfig(
), nil
}

// RegisterOperatorInQuorumWithAVSRegistryCoordinator
// TODO(samlaf): an operator that is already registered in a quorum can register with another quorum without passing
// signatures perhaps we should add another sdk function for this purpose, that just takes in a quorumNumber and
// socket? RegisterOperatorInQuorumWithAVSRegistryCoordinator is used to register a single operator with the AVS's
shrimalmadhur marked this conversation as resolved.
Show resolved Hide resolved
// registry coordinator. - operatorEcdsaPrivateKey is the operator's ecdsa private key (used to sign a message to
// register operator in eigenlayer's delegation manager)
// - operatorToAvsRegistrationSigSalt is a random salt used to prevent replay attacks
// - operatorToAvsRegistrationSigExpiry is the expiry time of the signature
//
// Deprecated: use RegisterOperator instead.
// We will only keep high-level functionality such as RegisterOperator, and low level functionality
// such as this function should eventually all be done with bindings directly instead.
func (w *ChainWriter) RegisterOperatorInQuorumWithAVSRegistryCoordinator(
ctx context.Context,
// we need to pass the private key explicitly and can't use the signer because registering requires signing a
Expand Down Expand Up @@ -340,6 +289,8 @@ func (w *ChainWriter) RegisterOperatorInQuorumWithAVSRegistryCoordinator(
return receipt, nil
}

// RegisterOperator is similar to RegisterOperatorInQuorumWithAVSRegistryCoordinator but
// generates a random salt and expiry for the signature.
func (w *ChainWriter) RegisterOperator(
ctx context.Context,
// we need to pass the private key explicitly and can't use the signer because registering requires signing a
Expand Down Expand Up @@ -457,6 +408,11 @@ func (w *ChainWriter) RegisterOperator(
return receipt, nil
}

// UpdateStakesOfEntireOperatorSetForQuorums is used by avs teams running https://github.com/Layr-Labs/avs-sync
// to updates the stake of their entire operator set.
// Because of high gas costs of this operation, it typically needs to be called for every quorum, or perhaps for a
// small grouping of quorums
// (highly dependent on number of operators per quorum)
func (w *ChainWriter) UpdateStakesOfEntireOperatorSetForQuorums(
ctx context.Context,
operatorsPerQuorum [][]gethcommon.Address,
Expand Down
3 changes: 0 additions & 3 deletions chainio/gen.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package chainio

//go:generate mockgen -destination=./mocks/avsRegistryContractsReader.go -package=mocks -mock_names=Reader=MockAVSReader github.com/Layr-Labs/eigensdk-go/chainio/clients/avsregistry Reader
//go:generate mockgen -destination=./mocks/avsRegistryContractsSubscriber.go -package=mocks -mock_names=Subscriber=MockAVSSubscriber github.com/Layr-Labs/eigensdk-go/chainio/clients/avsregistry Subscriber
//go:generate mockgen -destination=./mocks/avsRegistryContractsWriter.go -package=mocks -mock_names=Writer=MockAVSWriter github.com/Layr-Labs/eigensdk-go/chainio/clients/avsregistry Writer
//go:generate mockgen -destination=./mocks/ethclient.go -package=mocks -mock_names=Client=MockEthClient github.com/Layr-Labs/eigensdk-go/chainio/clients/eth Client
//go:generate mockgen -destination=./mocks/eventSubscription.go -package=mocks github.com/ethereum/go-ethereum/event Subscription
//go:generate mockgen -destination=./clients/mocks/fireblocks.go -package=mocks -mock_names=Client=MockFireblocksClient github.com/Layr-Labs/eigensdk-go/chainio/clients/fireblocks Client
Expand Down
Loading