diff --git a/go.mod b/go.mod index e0283ab8..e7c1a901 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21.0 require ( github.com/AlecAivazis/survey/v2 v2.3.7 - github.com/Layr-Labs/eigensdk-go v0.0.8 + github.com/Layr-Labs/eigensdk-go v0.0.9 github.com/ethereum/go-ethereum v1.13.5 github.com/stretchr/testify v1.8.4 github.com/urfave/cli/v2 v2.26.0 @@ -32,7 +32,7 @@ require ( github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-stack/stack v1.8.1 // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/google/uuid v1.4.0 // indirect + github.com/google/uuid v1.5.0 // indirect github.com/gorilla/websocket v1.4.2 // indirect github.com/holiman/uint256 v1.2.3 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect diff --git a/go.sum b/go.sum index 14e30c3d..88db0370 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkk github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo= github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= -github.com/Layr-Labs/eigensdk-go v0.0.8 h1:ZQF9xyKMfyftYq3RHXLKtznL6kHwZiOH5ZQZ/3ZUDXo= -github.com/Layr-Labs/eigensdk-go v0.0.8/go.mod h1:o+n2hLtZ5zWMYwrHygkkfoNRU4ZLGMYMFaL2+cHBBVk= +github.com/Layr-Labs/eigensdk-go v0.0.9 h1:IMtRQzEYhOHWYrwso6ko026D5/MF3YGtFCR4/b1l80s= +github.com/Layr-Labs/eigensdk-go v0.0.9/go.mod h1:oVDbRfA2GKFyZLf61zFOA3U2pjazHIFohlW7luDWqUA= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s= @@ -86,8 +86,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= -github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= -github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= +github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE= diff --git a/pkg/operator/register.go b/pkg/operator/register.go index 5a680d69..b6dda5d4 100644 --- a/pkg/operator/register.go +++ b/pkg/operator/register.go @@ -5,15 +5,17 @@ import ( "fmt" "math/big" + "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" + "github.com/Layr-Labs/eigensdk-go/signerv2" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/Layr-Labs/eigenlayer-cli/pkg/types" "github.com/Layr-Labs/eigenlayer-cli/pkg/utils" - eigenChainio "github.com/Layr-Labs/eigensdk-go/chainio/clients" + elContracts "github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts" "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" - elContracts "github.com/Layr-Labs/eigensdk-go/chainio/elcontracts" "github.com/Layr-Labs/eigensdk-go/crypto/bls" eigensdkLogger "github.com/Layr-Labs/eigensdk-go/logging" "github.com/Layr-Labs/eigensdk-go/metrics" - "github.com/Layr-Labs/eigensdk-go/signer" eigensdkUtils "github.com/Layr-Labs/eigensdk-go/utils" "github.com/ethereum/go-ethereum/common" "github.com/urfave/cli/v2" @@ -48,18 +50,13 @@ func RegisterCmd(p utils.Prompter) *cli.Command { operatorCfg.Operator.Address, utils.EmojiCheckMark, ) - fmt.Printf("validating operator config: %s %s\n", operatorCfg.Operator.Address, utils.EmojiInfo) + fmt.Printf("validating operator config: %s %s\n", operatorCfg.Operator.Address, utils.EmojiWait) err = operatorCfg.Operator.Validate() if err != nil { return fmt.Errorf("%w: with error %s", ErrInvalidYamlFile, err) } - signerType, err := validateSignerType(operatorCfg) - if err != nil { - return err - } - fmt.Printf( "Operator configuration file validated successfully %s %s\n", operatorCfg.Operator.Address, @@ -72,11 +69,6 @@ func RegisterCmd(p utils.Prompter) *cli.Command { return err } - localSigner, err := getSigner(p, signerType, operatorCfg) - if err != nil { - return err - } - blsKeyPassword, err := p.InputHiddenString("Enter password to decrypt the bls private key:", "", func(password string) error { return nil @@ -97,38 +89,51 @@ func RegisterCmd(p utils.Prompter) *cli.Command { return err } - elContractsClient, err := eigenChainio.NewELContractsChainClient( - common.HexToAddress(operatorCfg.ELSlasherAddress), - common.HexToAddress(operatorCfg.BlsPublicKeyCompendiumAddress), - ethClient, - ethClient, - logger) + ecdsaPassword, err := p.InputHiddenString("Enter password to decrypt the ecdsa private key:", "", + func(password string) error { + return nil + }, + ) + if err != nil { + fmt.Println("Error while reading ecdsa key password") + return err + } + + signerCfg := signerv2.Config{ + KeystorePath: operatorCfg.PrivateKeyStorePath, + Password: ecdsaPassword, + } + sgn, sender, err := signerv2.SignerFromConfig(signerCfg, &operatorCfg.ChainId) if err != nil { return err } + txMgr := txmgr.NewSimpleTxManager(ethClient, logger, sgn, sender) noopMetrics := metrics.NewNoopMetrics() - elWriter := elContracts.NewELChainWriter( - elContractsClient, + + elWriter, err := elContracts.BuildELChainWriter( + common.HexToAddress(operatorCfg.ELSlasherAddress), + common.HexToAddress(operatorCfg.BlsPublicKeyCompendiumAddress), ethClient, - localSigner, logger, noopMetrics, - ) + txMgr) + if err != nil { return err } - reader, err := elContracts.NewELChainReader( - elContractsClient, - logger, + reader, err := elContracts.BuildELChainReader( + common.HexToAddress(operatorCfg.ELSlasherAddress), + common.HexToAddress(operatorCfg.BlsPublicKeyCompendiumAddress), ethClient, + logger, ) if err != nil { return err } - status, err := reader.IsOperatorRegistered(ctx, operatorCfg.Operator) + status, err := reader.IsOperatorRegistered(&bind.CallOpts{Context: ctx}, operatorCfg.Operator) if err != nil { return err } @@ -168,48 +173,6 @@ func RegisterCmd(p utils.Prompter) *cli.Command { return registerCmd } -func validateSignerType(operatorCfg types.OperatorConfig) (types.SignerType, error) { - signerType := string(operatorCfg.SignerType) - - switch signerType { - case string(types.PrivateKeySigner): - return types.PrivateKeySigner, nil - case string(types.LocalKeystoreSigner): - return types.LocalKeystoreSigner, nil - default: - return "", fmt.Errorf("invalid signer type %s", signerType) - } -} - -func getSigner(p utils.Prompter, signerType types.SignerType, operatorCfg types.OperatorConfig) (signer.Signer, error) { - switch signerType { - case types.LocalKeystoreSigner: - fmt.Println("Using local keystore signer") - ecdsaPassword, err := p.InputHiddenString("Enter password to decrypt the ecdsa private key:", "", - func(password string) error { - return nil - }, - ) - if err != nil { - fmt.Println("Error while reading ecdsa key password") - return nil, err - } - // TODO: Get chain ID from config - localSigner, err := signer.NewPrivateKeyFromKeystoreSigner( - operatorCfg.PrivateKeyStorePath, - ecdsaPassword, - &operatorCfg.ChainId, - ) - if err != nil { - return nil, err - } - return localSigner, nil - - default: - return nil, fmt.Errorf("invalid signer type %s", signerType) - } -} - func getTransactionLink(txHash string, chainId *big.Int) string { // Create chainId for eth and goerli ethChainId := big.NewInt(1) diff --git a/pkg/operator/status.go b/pkg/operator/status.go index 1ee3c43d..c6e44b31 100644 --- a/pkg/operator/status.go +++ b/pkg/operator/status.go @@ -4,11 +4,12 @@ import ( "context" "fmt" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/Layr-Labs/eigenlayer-cli/pkg/types" "github.com/Layr-Labs/eigenlayer-cli/pkg/utils" - eigenChainio "github.com/Layr-Labs/eigensdk-go/chainio/clients" + elContracts "github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts" "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" - elContracts "github.com/Layr-Labs/eigensdk-go/chainio/elcontracts" eigensdkLogger "github.com/Layr-Labs/eigensdk-go/logging" eigensdkTypes "github.com/Layr-Labs/eigensdk-go/types" eigensdkUtils "github.com/Layr-Labs/eigensdk-go/utils" @@ -43,7 +44,7 @@ func StatusCmd(p utils.Prompter) *cli.Command { operatorCfg.Operator.Address, utils.EmojiCheckMark, ) - fmt.Printf("validating operator config: %s %s\n", operatorCfg.Operator.Address, utils.EmojiInfo) + fmt.Printf("validating operator config: %s %s\n", operatorCfg.Operator.Address, utils.EmojiWait) err = operatorCfg.Operator.Validate() if err != nil { @@ -66,38 +67,31 @@ func StatusCmd(p utils.Prompter) *cli.Command { return err } - elContractsClient, err := eigenChainio.NewELContractsChainClient( + reader, err := elContracts.BuildELChainReader( common.HexToAddress(operatorCfg.ELSlasherAddress), common.HexToAddress(operatorCfg.BlsPublicKeyCompendiumAddress), ethClient, - ethClient, - logger) - if err != nil { - return err - } - - reader, err := elContracts.NewELChainReader( - elContractsClient, logger, - ethClient, ) if err != nil { return err } - status, err := reader.IsOperatorRegistered(context.Background(), operatorCfg.Operator) + callOpts := &bind.CallOpts{Context: context.Background()} + + status, err := reader.IsOperatorRegistered(callOpts, operatorCfg.Operator) if err != nil { return err } if status { fmt.Printf("Operator is registered on EigenLayer %s\n", utils.EmojiCheckMark) - operatorDetails, err := reader.GetOperatorDetails(context.Background(), operatorCfg.Operator) + operatorDetails, err := reader.GetOperatorDetails(callOpts, operatorCfg.Operator) if err != nil { return err } printOperatorDetails(operatorDetails) - hash, err := reader.GetOperatorPubkeyHash(context.Background(), operatorCfg.Operator) + hash, err := reader.GetOperatorPubkeyHash(callOpts, operatorCfg.Operator) if err != nil { return err } diff --git a/pkg/operator/update.go b/pkg/operator/update.go index 8fed288b..53fe85b3 100644 --- a/pkg/operator/update.go +++ b/pkg/operator/update.go @@ -4,11 +4,13 @@ import ( "context" "fmt" + "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" + "github.com/Layr-Labs/eigensdk-go/signerv2" + "github.com/Layr-Labs/eigenlayer-cli/pkg/types" "github.com/Layr-Labs/eigenlayer-cli/pkg/utils" - eigenChainio "github.com/Layr-Labs/eigensdk-go/chainio/clients" + elContracts "github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts" "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" - elContracts "github.com/Layr-Labs/eigensdk-go/chainio/elcontracts" eigensdkLogger "github.com/Layr-Labs/eigensdk-go/logging" "github.com/Layr-Labs/eigensdk-go/metrics" eigensdkUtils "github.com/Layr-Labs/eigensdk-go/utils" @@ -47,49 +49,51 @@ func UpdateCmd(p utils.Prompter) *cli.Command { operatorCfg.Operator.Address, utils.EmojiCheckMark, ) - signerType, err := validateSignerType(operatorCfg) - if err != nil { - return err - } logger, err := eigensdkLogger.NewZapLogger(eigensdkLogger.Development) if err != nil { return err } - localSigner, err := getSigner(p, signerType, operatorCfg) + ethClient, err := eth.NewClient(operatorCfg.EthRPCUrl) if err != nil { return err } - ethClient, err := eth.NewClient(operatorCfg.EthRPCUrl) + ecdsaPassword, err := p.InputHiddenString("Enter password to decrypt the ecdsa private key:", "", + func(password string) error { + return nil + }, + ) if err != nil { + fmt.Println("Error while reading ecdsa key password") return err } - elContractsClient, err := eigenChainio.NewELContractsChainClient( - common.HexToAddress(operatorCfg.ELSlasherAddress), - common.HexToAddress(operatorCfg.BlsPublicKeyCompendiumAddress), - ethClient, - ethClient, - logger, - ) + signerCfg := signerv2.Config{ + KeystorePath: operatorCfg.PrivateKeyStorePath, + Password: ecdsaPassword, + } + sgn, sender, err := signerv2.SignerFromConfig(signerCfg, &operatorCfg.ChainId) if err != nil { return err } + txMgr := txmgr.NewSimpleTxManager(ethClient, logger, sgn, sender) noopMetrics := metrics.NewNoopMetrics() - elWriter := elContracts.NewELChainWriter( - elContractsClient, + + elWriter, err := elContracts.BuildELChainWriter( + common.HexToAddress(operatorCfg.ELSlasherAddress), + common.HexToAddress(operatorCfg.BlsPublicKeyCompendiumAddress), ethClient, - localSigner, logger, noopMetrics, - ) + txMgr) if err != nil { return err } + receipt, err := elWriter.UpdateOperatorDetails(context.Background(), operatorCfg.Operator) if err != nil { logger.Errorf("Error while updating operator details: %s", utils.EmojiCrossMark)