Skip to content

Commit

Permalink
support set claimer
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur committed Jun 27, 2024
1 parent f57d0da commit 60dcd38
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 25 deletions.
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ module github.com/Layr-Labs/eigenlayer-cli

go 1.21.11

replace (
github.com/Layr-Labs/eigensdk-go v0.1.7 => /Users/madhurshrimal/Desktop/github/Layr-Labs/eigensdk-go
)

require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/Layr-Labs/eigensdk-go v0.1.7
Expand Down
1 change: 1 addition & 0 deletions pkg/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func OperatorCmd(p utils.Prompter) *cli.Command {
operator.RegisterCmd(p),
operator.StatusCmd(p),
operator.UpdateCmd(p),
operator.SetClaimerCmd(p),
},
}

Expand Down
21 changes: 21 additions & 0 deletions pkg/operator/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package operator

import "github.com/urfave/cli/v2"

var (
ConfigurationFilePathFlag = cli.StringFlag{
Name: "configuration-file",
Aliases: []string{"c"},
Usage: "Path to the configuration file",
Required: true,
EnvVars: []string{"NODE_OPERATOR_CONFIG_FILE"},
}

ClaimerAddressFlag = cli.StringFlag{
Name: "claimer-address",
Aliases: []string{"a"},
Usage: "Address of the claimer",
Required: true,
EnvVars: []string{"NODE_OPERATOR_CLAIMER_ADDRESS"},
}
)
16 changes: 16 additions & 0 deletions pkg/operator/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ func readConfigFile(path string) (*types.OperatorConfig, error) {
return nil, err
}
operatorCfg.ELAVSDirectoryAddress = elAVSDirectoryAddress

elRewardsCoordinatorAddress, err := getRewardCoordinatorAddress(operatorCfg.ChainId)
if err != nil {
return nil, err
}
operatorCfg.ELRewardsCoordinatorAddress = elRewardsCoordinatorAddress
return &operatorCfg, nil
}

Expand All @@ -351,6 +357,16 @@ func getAVSDirectoryAddress(chainID big.Int) (string, error) {
}
}

func getRewardCoordinatorAddress(chainID big.Int) (string, error) {
chainIDInt := chainID.Int64()
chainMetadata, ok := utils.ChainMetadataMap[chainIDInt]
if !ok {
return "", fmt.Errorf("chain ID %d not supported", chainIDInt)
} else {
return chainMetadata.ELRewardsCoordinatorAddress, nil
}
}

func getTransactionLink(txHash string, chainId *big.Int) string {
chainIDInt := chainId.Int64()
chainMetadata, ok := utils.ChainMetadataMap[chainIDInt]
Expand Down
98 changes: 98 additions & 0 deletions pkg/operator/setclaimer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package operator

import (
"context"
"fmt"

"github.com/Layr-Labs/eigenlayer-cli/pkg/telemetry"
"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"

"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"
eigensdkLogger "github.com/Layr-Labs/eigensdk-go/logging"
eigenMetrics "github.com/Layr-Labs/eigensdk-go/metrics"

"github.com/ethereum/go-ethereum/common"

"github.com/urfave/cli/v2"
)

func SetClaimerCmd(p utils.Prompter) *cli.Command {
setClaimerCmd := &cli.Command{
Name: "set-claimer",
Usage: "Set the claimer address for the operator",
UsageText: "set-claimer",
Description: `
Set the rewards claimer address for the operator.
`,
After: telemetry.AfterRunAction(),
Flags: []cli.Flag{
&ConfigurationFilePathFlag,
&ClaimerAddressFlag,
},
Action: func(cCtx *cli.Context) error {
configurationFilePath := cCtx.String(ConfigurationFilePathFlag.Name)
claimerAddress := cCtx.String(ClaimerAddressFlag.Name)

operatorCfg, err := validateAndReturnConfig(configurationFilePath)
if err != nil {
return err
}
cCtx.App.Metadata["network"] = operatorCfg.ChainId.String()

logger, err := eigensdkLogger.NewZapLogger(eigensdkLogger.Development)
if err != nil {
return err
}

ethClient, err := eth.NewClient(operatorCfg.EthRPCUrl)
if err != nil {
return err
}

keyWallet, sender, err := getWallet(operatorCfg, ethClient, p, logger)
if err != nil {
return err
}

txMgr := txmgr.NewSimpleTxManager(keyWallet, ethClient, logger, sender)

noopMetrics := eigenMetrics.NewNoopMetrics()

contractCfg := elcontracts.Config{
DelegationManagerAddress: common.HexToAddress(operatorCfg.ELDelegationManagerAddress),
AvsDirectoryAddress: common.HexToAddress(operatorCfg.ELAVSDirectoryAddress),
RewardsCoordinatorAddress: common.HexToAddress(operatorCfg.ELRewardsCoordinatorAddress),
}
fmt.Println(operatorCfg)

elWriter, err := elcontracts.NewWriterFromConfig(contractCfg, ethClient, logger, noopMetrics, txMgr)
if err != nil {
return err
}

receipt, err := elWriter.SetClaimerFor(context.Background(), common.HexToAddress(claimerAddress))
if err != nil {
return err
}

fmt.Printf(
"%s Claimer address %s set successfully for operator %s\n",
utils.EmojiCheckMark,
claimerAddress,
operatorCfg.Operator.Address,
)

printRegistrationInfo(
receipt.TxHash.String(),
common.HexToAddress(operatorCfg.Operator.Address),
&operatorCfg.ChainId,
)

return nil
},
}

return setClaimerCmd
}
9 changes: 5 additions & 4 deletions pkg/types/chain_metadata.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package types

type ChainMetadata struct {
BlockExplorerUrl string
ELDelegationManagerAddress string
ELAVSDirectoryAddress string
WebAppUrl string
BlockExplorerUrl string
ELDelegationManagerAddress string
ELAVSDirectoryAddress string
ELRewardsCoordinatorAddress string
WebAppUrl string
}
19 changes: 10 additions & 9 deletions pkg/types/operator_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ type Web3SignerConfig struct {
}

type OperatorConfig struct {
Operator eigensdkTypes.Operator `yaml:"operator"`
ELDelegationManagerAddress string `yaml:"el_delegation_manager_address"`
ELAVSDirectoryAddress string
EthRPCUrl string `yaml:"eth_rpc_url"`
PrivateKeyStorePath string `yaml:"private_key_store_path"`
SignerType SignerType `yaml:"signer_type"`
ChainId big.Int `yaml:"chain_id"`
FireblocksConfig FireblocksConfig `yaml:"fireblocks"`
Web3SignerConfig Web3SignerConfig `yaml:"web3"`
Operator eigensdkTypes.Operator `yaml:"operator"`
ELDelegationManagerAddress string `yaml:"el_delegation_manager_address"`
ELAVSDirectoryAddress string
ELRewardsCoordinatorAddress string
EthRPCUrl string `yaml:"eth_rpc_url"`
PrivateKeyStorePath string `yaml:"private_key_store_path"`
SignerType SignerType `yaml:"signer_type"`
ChainId big.Int `yaml:"chain_id"`
FireblocksConfig FireblocksConfig `yaml:"fireblocks"`
Web3SignerConfig Web3SignerConfig `yaml:"web3"`
}

func (config OperatorConfig) MarshalYAML() (interface{}, error) {
Expand Down
27 changes: 15 additions & 12 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,25 @@ import (

var ChainMetadataMap = map[int64]types.ChainMetadata{
MainnetChainId: {
BlockExplorerUrl: "https://etherscan.io/tx",
ELDelegationManagerAddress: "0x39053D51B77DC0d36036Fc1fCc8Cb819df8Ef37A",
ELAVSDirectoryAddress: "0x135dda560e946695d6f155dacafc6f1f25c1f5af",
WebAppUrl: "https://app.eigenlayer.xyz/operator",
BlockExplorerUrl: "https://etherscan.io/tx",
ELDelegationManagerAddress: "0x39053D51B77DC0d36036Fc1fCc8Cb819df8Ef37A",
ELAVSDirectoryAddress: "0x135dda560e946695d6f155dacafc6f1f25c1f5af",
ELRewardsCoordinatorAddress: "",
WebAppUrl: "https://app.eigenlayer.xyz/operator",
},
HoleskyChainId: {
BlockExplorerUrl: "https://holesky.etherscan.io/tx",
ELDelegationManagerAddress: "0xA44151489861Fe9e3055d95adC98FbD462B948e7",
ELAVSDirectoryAddress: "0x055733000064333CaDDbC92763c58BF0192fFeBf",
WebAppUrl: "https://holesky.eigenlayer.xyz/operator",
BlockExplorerUrl: "https://holesky.etherscan.io/tx",
ELDelegationManagerAddress: "0xA44151489861Fe9e3055d95adC98FbD462B948e7",
ELAVSDirectoryAddress: "0x055733000064333CaDDbC92763c58BF0192fFeBf",
ELRewardsCoordinatorAddress: "0xb22Ef643e1E067c994019A4C19e403253C05c2B0",
WebAppUrl: "https://holesky.eigenlayer.xyz/operator",
},
LocalChainId: {
BlockExplorerUrl: "",
ELDelegationManagerAddress: "",
ELAVSDirectoryAddress: "",
WebAppUrl: "",
BlockExplorerUrl: "",
ELDelegationManagerAddress: "",
ELAVSDirectoryAddress: "",
ELRewardsCoordinatorAddress: "",
WebAppUrl: "",
},
}

Expand Down

0 comments on commit 60dcd38

Please sign in to comment.