Skip to content

Commit

Permalink
Adding interface EthClientInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodeymo committed Oct 14, 2024
1 parent fef94ea commit 4e03208
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 22 deletions.
26 changes: 26 additions & 0 deletions common/abi.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
package common

import (
"context"
_ "embed"
"math/big"

"github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

//go:embed abis/IncredibleSquaringTaskManager.json
var IncredibleSquaringTaskManagerAbi []byte

type EthClientInterface interface {
wallet.EthBackend
TransactionByHash(context.Context, common.Hash) (*types.Transaction, bool, error)
ChainID(ctx context.Context) (*big.Int, error)

SuggestGasTipCap(ctx context.Context) (*big.Int, error)
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error)
CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
BlockNumber(ctx context.Context) (uint64, error)
CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)
PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error)
PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
SuggestGasPrice(ctx context.Context) (*big.Int, error)
}
11 changes: 6 additions & 5 deletions core/chainio/avs_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"math/big"

sdkcommon "github.com/Layr-Labs/incredible-squaring-avs/common"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"

Expand Down Expand Up @@ -48,19 +49,19 @@ type AvsWriter struct {
client eth.HttpBackend
}

//var _ AvsWriterer = (*AvsWriter)(nil)
var _ AvsWriterer = (*AvsWriter)(nil)

func BuildAvsWriterFromConfig(c *config.Config) (*AvsWriter, error) {
return BuildAvsWriter(c.TxMgr, c.IncredibleSquaringRegistryCoordinatorAddr, c.OperatorStateRetrieverAddr, c.EthHttpClient, c.Logger)
return BuildAvsWriter(c.TxMgr, c.IncredibleSquaringRegistryCoordinatorAddr, c.OperatorStateRetrieverAddr, &c.EthHttpClient, c.Logger)
}

func BuildAvsWriter(txMgr txmgr.TxManager, registryCoordinatorAddr, operatorStateRetrieverAddr gethcommon.Address, ethHttpClient eth.InstrumentedClient, logger logging.Logger) (*AvsWriter, error) {
avsServiceBindings, err := NewAvsManagersBindings(registryCoordinatorAddr, operatorStateRetrieverAddr, &ethHttpClient, logger)
func BuildAvsWriter(txMgr txmgr.TxManager, registryCoordinatorAddr, operatorStateRetrieverAddr gethcommon.Address, ethHttpClient sdkcommon.EthClientInterface, logger logging.Logger) (*AvsWriter, error) {
avsServiceBindings, err := NewAvsManagersBindings(registryCoordinatorAddr, operatorStateRetrieverAddr, ethHttpClient, logger)
if err != nil {
logger.Error("Failed to create contract bindings", "err", err)
return nil, err
}
avsRegistryWriter, err := avsregistry.BuildAvsRegistryChainWriter(registryCoordinatorAddr, operatorStateRetrieverAddr, logger, &ethHttpClient, txMgr)
avsRegistryWriter, err := avsregistry.BuildAvsRegistryChainWriter(registryCoordinatorAddr, operatorStateRetrieverAddr, logger, ethHttpClient, txMgr)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion core/chainio/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
gethcommon "github.com/ethereum/go-ethereum/common"

regcoord "github.com/Layr-Labs/eigensdk-go/contracts/bindings/RegistryCoordinator"
sdkcommon "github.com/Layr-Labs/incredible-squaring-avs/common"
erc20mock "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/ERC20Mock"
csservicemanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/IncredibleSquaringServiceManager"
cstaskmanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/IncredibleSquaringTaskManager"
Expand All @@ -21,7 +22,7 @@ type AvsManagersBindings struct {
logger logging.Logger
}

func NewAvsManagersBindings(registryCoordinatorAddr, operatorStateRetrieverAddr gethcommon.Address, ethclient eth.HttpBackend, logger logging.Logger) (*AvsManagersBindings, error) {
func NewAvsManagersBindings(registryCoordinatorAddr, operatorStateRetrieverAddr gethcommon.Address, ethclient sdkcommon.EthClientInterface, logger logging.Logger) (*AvsManagersBindings, error) {
contractRegistryCoordinator, err := regcoord.NewContractRegistryCoordinator(registryCoordinatorAddr, ethclient)
if err != nil {
return nil, err
Expand Down
5 changes: 2 additions & 3 deletions core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Config struct {
// only take an ethclient or an rpcUrl (and build the ethclient at each constructor site)
EthHttpRpcUrl string
EthWsRpcUrl string
EthHttpClient eth.InstrumentedClient
EthHttpClient ethclient.Client
EthWsClient eth.WsBackend
OperatorStateRetrieverAddr common.Address
IncredibleSquaringRegistryCoordinatorAddr common.Address
Expand Down Expand Up @@ -90,7 +90,6 @@ func NewConfig(ctx *cli.Context) (*Config, error) {
logger.Errorf("Cannot create http ethclient", "err", err)
return nil, err
}
ethRpcClientInstrumented := eth.NewInstrumentedClientFromClient(ethRpcClient, nil)

ethWsClient, err := ethclient.Dial(configRaw.EthWsUrl)
if err != nil {
Expand Down Expand Up @@ -135,7 +134,7 @@ func NewConfig(ctx *cli.Context) (*Config, error) {
Logger: logger,
EthWsRpcUrl: configRaw.EthWsUrl,
EthHttpRpcUrl: configRaw.EthRpcUrl,
EthHttpClient: *ethRpcClientInstrumented,
EthHttpClient: *ethRpcClient,
EthWsClient: ethWsClient,
OperatorStateRetrieverAddr: common.HexToAddress(credibleSquaringDeploymentRaw.Addresses.OperatorStateRetrieverAddr),
IncredibleSquaringRegistryCoordinatorAddr: common.HexToAddress(credibleSquaringDeploymentRaw.Addresses.RegistryCoordinatorAddr),
Expand Down
14 changes: 8 additions & 6 deletions operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/prometheus/client_golang/prometheus"

"github.com/Layr-Labs/incredible-squaring-avs/aggregator"
sdkcommon "github.com/Layr-Labs/incredible-squaring-avs/common"
cstaskmanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/IncredibleSquaringTaskManager"
"github.com/Layr-Labs/incredible-squaring-avs/core"
"github.com/Layr-Labs/incredible-squaring-avs/core/chainio"
Expand Down Expand Up @@ -40,7 +42,7 @@ const SEM_VER = "0.0.1"
type Operator struct {
config types.NodeConfig
logger logging.Logger
ethClient eth.InstrumentedClient
ethClient sdkcommon.EthClientInterface
// TODO(samlaf): remove both avsWriter and eigenlayerWrite from operator
// they are only used for registration, so we should make a special registration package
// this way, auditing this operator code makes it obvious that operators don't need to
Expand Down Expand Up @@ -88,7 +90,7 @@ func NewOperatorFromConfig(c types.NodeConfig) (*Operator, error) {
// Setup Node Api
nodeApi := nodeapi.NewNodeApi(AVS_NAME, SEM_VER, c.NodeApiIpPortAddress, logger)

var ethRpcClient, ethWsClient *eth.InstrumentedClient
var ethRpcClient, ethWsClient sdkcommon.EthClientInterface
if c.EnableMetrics {
rpcCallsCollector := rpccalls.NewCollector(AVS_NAME, reg)
ethRpcClient, err = eth.NewInstrumentedClient(c.EthRpcUrl, rpcCallsCollector)
Expand All @@ -102,12 +104,12 @@ func NewOperatorFromConfig(c types.NodeConfig) (*Operator, error) {
return nil, err
}
} else {
ethRpcClient, err = eth.NewInstrumentedClient(c.EthRpcUrl, nil)
ethRpcClient, err = ethclient.Dial(c.EthRpcUrl)
if err != nil {
logger.Errorf("Cannot create http ethclient", "err", err)
return nil, err
}
ethWsClient, err = eth.NewInstrumentedClient(c.EthWsUrl, nil)
ethWsClient, err = ethclient.Dial(c.EthWsUrl)
if err != nil {
logger.Errorf("Cannot create ws ethclient", "err", err)
return nil, err
Expand Down Expand Up @@ -171,7 +173,7 @@ func NewOperatorFromConfig(c types.NodeConfig) (*Operator, error) {

avsWriter, err := chainio.BuildAvsWriter(
txMgr, common.HexToAddress(c.AVSRegistryCoordinatorAddress),
common.HexToAddress(c.OperatorStateRetrieverAddress), *ethRpcClient, logger,
common.HexToAddress(c.OperatorStateRetrieverAddress), ethRpcClient, logger,
)
if err != nil {
logger.Error("Cannot create AvsWriter", "err", err)
Expand Down Expand Up @@ -216,7 +218,7 @@ func NewOperatorFromConfig(c types.NodeConfig) (*Operator, error) {
metricsReg: reg,
metrics: avsAndEigenMetrics,
nodeApi: nodeApi,
ethClient: *ethRpcClient,
ethClient: ethRpcClient,
avsWriter: avsWriter,
avsReader: avsReader,
avsSubscriber: avsSubscriber,
Expand Down
4 changes: 1 addition & 3 deletions plugin/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

sdkclients "github.com/Layr-Labs/eigensdk-go/chainio/clients"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet"
"github.com/Layr-Labs/eigensdk-go/chainio/txmgr"
regcoord "github.com/Layr-Labs/eigensdk-go/contracts/bindings/RegistryCoordinator"
Expand Down Expand Up @@ -153,12 +152,11 @@ func plugin(ctx *cli.Context) {
return
}
txMgr := txmgr.NewSimpleTxManager(skWallet, ethHttpClient, logger, common.HexToAddress(avsConfig.OperatorAddress))
ethRpcClientInstrumented := eth.NewInstrumentedClientFromClient(ethHttpClient, nil)
avsWriter, err := chainio.BuildAvsWriter(
txMgr,
common.HexToAddress(avsConfig.AVSRegistryCoordinatorAddress),
common.HexToAddress(avsConfig.OperatorStateRetrieverAddress),
*ethRpcClientInstrumented,
ethHttpClient,
logger,
)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/Layr-Labs/eigensdk-go/chainio/clients"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet"
"github.com/Layr-Labs/eigensdk-go/chainio/txmgr"
sdklogging "github.com/Layr-Labs/eigensdk-go/logging"
Expand Down Expand Up @@ -98,13 +97,11 @@ func TestIntegration(t *testing.T) {
}
txMgr := txmgr.NewSimpleTxManager(skWallet, ethRpcClient, logger, aggregatorAddr)

ethRpcClientInstrumented := eth.NewInstrumentedClientFromClient(ethRpcClient, nil)

config := &config.Config{
EcdsaPrivateKey: aggregatorEcdsaPrivateKey,
Logger: logger,
EthHttpRpcUrl: aggConfigRaw.EthRpcUrl,
EthHttpClient: *ethRpcClientInstrumented,
EthHttpClient: *ethRpcClient,
EthWsRpcUrl: aggConfigRaw.EthWsUrl,
EthWsClient: ethWsClient,
OperatorStateRetrieverAddr: common.HexToAddress(credibleSquaringDeploymentRaw.Addresses.OperatorStateRetrieverAddr),
Expand Down

0 comments on commit 4e03208

Please sign in to comment.