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

move builders to it's own package #286

Merged
merged 7 commits into from
Jul 3, 2024
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
18 changes: 8 additions & 10 deletions chainio/clients/avsregistry/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,12 @@ func NewBindingsFromConfig(
var (
err error

serviceManagerAddr gethcommon.Address
registryCoordinatorAddr gethcommon.Address
stakeRegistryAddr gethcommon.Address
blsApkRegistryAddr gethcommon.Address
indexRegistryAddr gethcommon.Address
operatorStateRetrieverAddr gethcommon.Address
delegationManagerAddr gethcommon.Address
avsDirectoryAddr gethcommon.Address
serviceManagerAddr gethcommon.Address
stakeRegistryAddr gethcommon.Address
blsApkRegistryAddr gethcommon.Address
indexRegistryAddr gethcommon.Address
delegationManagerAddr gethcommon.Address
avsDirectoryAddr gethcommon.Address

contractBlsRegistryCoordinator *regcoordinator.ContractRegistryCoordinator
contractServiceManager *servicemanager.ContractServiceManagerBase
Expand Down Expand Up @@ -228,11 +226,11 @@ func NewBindingsFromConfig(

return &ContractBindings{
ServiceManagerAddr: serviceManagerAddr,
RegistryCoordinatorAddr: registryCoordinatorAddr,
RegistryCoordinatorAddr: cfg.RegistryCoordinatorAddress,
StakeRegistryAddr: stakeRegistryAddr,
BlsApkRegistryAddr: blsApkRegistryAddr,
IndexRegistryAddr: indexRegistryAddr,
OperatorStateRetrieverAddr: operatorStateRetrieverAddr,
OperatorStateRetrieverAddr: cfg.OperatorStateRetrieverAddress,
DelegationManagerAddr: delegationManagerAddr,
AvsDirectoryAddr: avsDirectoryAddr,
ServiceManager: contractServiceManager,
Expand Down
72 changes: 72 additions & 0 deletions chainio/clients/avsregistry/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package avsregistry

import (
"github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
"github.com/Layr-Labs/eigensdk-go/chainio/txmgr"
"github.com/Layr-Labs/eigensdk-go/logging"
)

func BuildClients(
config Config,
client eth.Client,
wsClient eth.Client,
txMgr txmgr.TxManager,
logger logging.Logger,
) (*ChainReader, *ChainSubscriber, *ChainWriter, *ContractBindings, error) {
avsBindings, err := NewBindingsFromConfig(
config,
client,
logger,
)

if err != nil {
return nil, nil, nil, nil, err
}

chainReader := NewChainReader(
samlaf marked this conversation as resolved.
Show resolved Hide resolved
avsBindings.RegistryCoordinatorAddr,
avsBindings.BlsApkRegistryAddr,
avsBindings.RegistryCoordinator,
avsBindings.OperatorStateRetriever,
avsBindings.StakeRegistry,
logger,
client,
)

chainSubscriber, err := NewSubscriberFromConfig(
config,
wsClient,
logger,
)
if err != nil {
return nil, nil, nil, nil, err
}

// This is ugly, but we need elReader to be able to create the AVS writer
elChainReader, err := elcontracts.NewReaderFromConfig(
elcontracts.Config{
DelegationManagerAddress: avsBindings.DelegationManagerAddr,
AvsDirectoryAddress: avsBindings.AvsDirectoryAddr,
},
client,
logger,
)
Comment on lines +47 to +54
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need this to be created outside and passed via dependency injection? Or could we just build it inside the NewChainWriter constructor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm good ques. idk. need to think more

if err != nil {
return nil, nil, nil, nil, err
}

chainWriter := NewChainWriter(
samlaf marked this conversation as resolved.
Show resolved Hide resolved
avsBindings.ServiceManagerAddr,
avsBindings.RegistryCoordinator,
avsBindings.OperatorStateRetriever,
avsBindings.StakeRegistry,
avsBindings.BlsApkRegistry,
elChainReader,
logger,
client,
txMgr,
)

return chainReader, chainSubscriber, chainWriter, avsBindings, nil
}
22 changes: 14 additions & 8 deletions chainio/clients/avsregistry/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@ type ChainSubscriber struct {
// 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(
logger logging.Logger,
regCoord regcoord.ContractRegistryCoordinatorFilters,
blsApkRegistry blsapkreg.ContractBLSApkRegistryFilters,
) (*ChainSubscriber, error) {
logger logging.Logger,
) *ChainSubscriber {
logger = logger.With(logging.ComponentKey, "avsregistry/ChainSubscriber")

return &ChainSubscriber{
logger: logger,
regCoord: regCoord,
blsApkRegistry: blsApkRegistry,
}, nil
logger: logger,
}
}

// BuildAvsRegistryChainSubscriber creates a new instance of ChainSubscriber
// Deprecated: Use NewSubscriberFromConfig instead
func BuildAvsRegistryChainSubscriber(
regCoordAddr common.Address,
ethWsClient eth.Client,
Expand All @@ -57,20 +61,22 @@ func BuildAvsRegistryChainSubscriber(
if err != nil {
return nil, utils.WrapError("Failed to create BLSApkRegistry contract", err)
}
return NewChainSubscriber(logger, regCoord, blsApkReg)
return NewChainSubscriber(regCoord, blsApkReg, logger), nil
}

// NewSubscriberFromConfig creates a new instance of ChainSubscriber
// A websocket ETH Client must be provided
func NewSubscriberFromConfig(
cfg Config,
ethClient eth.Client,
wsClient eth.Client,
logger logging.Logger,
) (*ChainSubscriber, error) {
bindings, err := NewBindingsFromConfig(cfg, ethClient, logger)
bindings, err := NewBindingsFromConfig(cfg, wsClient, logger)
if err != nil {
return nil, err
}

return NewChainSubscriber(logger, bindings.RegistryCoordinator, bindings.BlsApkRegistry)
return NewChainSubscriber(bindings.RegistryCoordinator, bindings.BlsApkRegistry, logger), nil
}

func (s *ChainSubscriber) SubscribeToNewPubkeyRegistrations() (chan *blsapkreg.ContractBLSApkRegistryNewPubkeyRegistration, event.Subscription, error) {
Expand Down
12 changes: 6 additions & 6 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type ChainWriter struct {
operatorStateRetriever *opstateretriever.ContractOperatorStateRetriever
stakeRegistry *stakeregistry.ContractStakeRegistry
blsApkRegistry *blsapkregistry.ContractBLSApkRegistry
elReader elcontracts.ELReader
elReader elcontracts.Reader
logger logging.Logger
ethClient eth.Client
txMgr txmgr.TxManager
Expand All @@ -108,11 +108,11 @@ func NewChainWriter(
operatorStateRetriever *opstateretriever.ContractOperatorStateRetriever,
stakeRegistry *stakeregistry.ContractStakeRegistry,
blsApkRegistry *blsapkregistry.ContractBLSApkRegistry,
elReader elcontracts.ELReader,
elReader elcontracts.Reader,
logger logging.Logger,
ethClient eth.Client,
txMgr txmgr.TxManager,
) (*ChainWriter, error) {
) *ChainWriter {
logger = logger.With(logging.ComponentKey, "avsregistry/ChainWriter")

return &ChainWriter{
Expand All @@ -125,7 +125,7 @@ func NewChainWriter(
logger: logger,
ethClient: ethClient,
txMgr: txMgr,
}, nil
}
}

// BuildAvsRegistryChainWriter creates a new ChainWriter instance from the provided contract addresses
Expand Down Expand Up @@ -194,7 +194,7 @@ func BuildAvsRegistryChainWriter(
logger,
ethClient,
txMgr,
)
), nil
}

// NewWriterFromConfig creates a new ChainWriter from the provided config
Expand Down Expand Up @@ -226,7 +226,7 @@ func NewWriterFromConfig(
logger,
client,
txMgr,
)
), nil
}

func (w *ChainWriter) RegisterOperatorInQuorumWithAVSRegistryCoordinator(
Expand Down
Loading
Loading