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

upgrade to eigensdk v0.0.9 #23

Merged
merged 2 commits into from
Dec 28, 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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
103 changes: 33 additions & 70 deletions pkg/operator/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 10 additions & 16 deletions pkg/operator/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
42 changes: 23 additions & 19 deletions pkg/operator/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
Loading