From 8207781130cb8043ceafe6880a42ae37e1f6b6b7 Mon Sep 17 00:00:00 2001 From: gpabst Date: Mon, 9 Dec 2024 17:04:33 -0500 Subject: [PATCH 01/13] feat: set operator split command --- go.mod | 4 +- go.sum | 6 +- pkg/rewards.go | 1 + pkg/rewards/flags.go | 18 +++- pkg/rewards/operator_split.go | 170 ++++++++++++++++++++++++++++++++++ pkg/rewards/types.go | 12 +++ 6 files changed, 204 insertions(+), 7 deletions(-) create mode 100644 pkg/rewards/operator_split.go diff --git a/go.mod b/go.mod index cbdc0230..98d17d82 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/Layr-Labs/eigenlayer-contracts v0.3.2-mainnet-rewards github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.12 github.com/Layr-Labs/eigenpod-proofs-generation v0.0.14-stable.0.20240730152248-5c11a259293e - github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241121204729-7d2cd162ffe8 + github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241209163655-6b1cbb153ef6 github.com/blang/semver/v4 v4.0.0 github.com/consensys/gnark-crypto v0.12.1 github.com/ethereum/go-ethereum v1.14.5 @@ -19,6 +19,7 @@ require ( github.com/tyler-smith/go-bip39 v1.1.0 github.com/urfave/cli/v2 v2.27.2 github.com/wagslane/go-password-validator v0.3.0 + github.com/wealdtech/go-merkletree/v2 v2.5.2-0.20240302222400-69219c450662 github.com/wk8/go-ordered-map/v2 v2.1.8 go.uber.org/mock v0.4.0 gopkg.in/yaml.v2 v2.4.0 @@ -100,7 +101,6 @@ require ( github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect - github.com/wealdtech/go-merkletree/v2 v2.5.2-0.20240302222400-69219c450662 // indirect github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect go.opentelemetry.io/otel v1.24.0 // indirect go.opentelemetry.io/otel/metric v1.24.0 // indirect diff --git a/go.sum b/go.sum index f893523b..fcf1f24f 100644 --- a/go.sum +++ b/go.sum @@ -12,10 +12,8 @@ github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.12 h1:G5Q1SnLmFbEjhOkky3vIHk github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.12/go.mod h1:OlJd1QjqEW53wfWG/lJyPCGvrXwWVEjPQsP4TV+gttQ= github.com/Layr-Labs/eigenpod-proofs-generation v0.0.14-stable.0.20240730152248-5c11a259293e h1:DvW0/kWHV9mZsbH2KOjEHKTSIONNPUj6X05FJvUohy4= github.com/Layr-Labs/eigenpod-proofs-generation v0.0.14-stable.0.20240730152248-5c11a259293e/go.mod h1:T7tYN8bTdca2pkMnz9G2+ZwXYWw5gWqQUIu4KLgC/vM= -github.com/Layr-Labs/eigensdk-go v0.1.13-0.20241023200243-565bb4438918 h1:Itl141PoMFzq58ZTo4Nu/CyH+x8f4BH6OmBNhZ6Z2/I= -github.com/Layr-Labs/eigensdk-go v0.1.13-0.20241023200243-565bb4438918/go.mod h1:aYdNURUhaqeYOS+Cq12TfSdPbjFfiLaHkxPdR4Exq/s= -github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241121204729-7d2cd162ffe8 h1:6wuVq+Elto+yF7bQ3QYqD2psxGXR3wcJh2koNcUjIQM= -github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241121204729-7d2cd162ffe8/go.mod h1:aYdNURUhaqeYOS+Cq12TfSdPbjFfiLaHkxPdR4Exq/s= +github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241209163655-6b1cbb153ef6 h1:qQk3QJ+I+ffHOpZvaEC1NULxl3Hfzi+ojpniBAmUdWg= +github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241209163655-6b1cbb153ef6/go.mod h1:aYdNURUhaqeYOS+Cq12TfSdPbjFfiLaHkxPdR4Exq/s= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8= diff --git a/pkg/rewards.go b/pkg/rewards.go index 81828aa3..f15467d8 100644 --- a/pkg/rewards.go +++ b/pkg/rewards.go @@ -14,6 +14,7 @@ func RewardsCmd(p utils.Prompter) *cli.Command { rewards.ClaimCmd(p), rewards.SetClaimerCmd(p), rewards.ShowCmd(p), + rewards.OperatorSplitCmd(p), }, } diff --git a/pkg/rewards/flags.go b/pkg/rewards/flags.go index 810b725d..fabc1e49 100644 --- a/pkg/rewards/flags.go +++ b/pkg/rewards/flags.go @@ -79,7 +79,7 @@ var ( AVSAddressesFlag = cli.StringFlag{ Name: "avs-addresses", - Aliases: []string{"a"}, + Aliases: []string{"aa"}, Usage: "Comma seperated addresses of the AVS", EnvVars: []string{"AVS_ADDRESSES"}, } @@ -91,4 +91,20 @@ var ( Value: "all", EnvVars: []string{"REWARDS_CLAIM_TYPE"}, } + + OperatorAddressFlag = cli.StringFlag{ + Name: "operator-address", + Aliases: []string{"a"}, + Usage: "Address of the operator", + Required: false, + EnvVars: []string{"REWARDS_OPERATOR_ADDRESS"}, + } + + OperatorSplitFlag = cli.IntFlag{ + Name: "operator-split", + Aliases: []string{"os"}, + Usage: "Split for the operator", + Required: false, + EnvVars: []string{"REWARDS_OPERATOR_SPLIT"}, + } ) diff --git a/pkg/rewards/operator_split.go b/pkg/rewards/operator_split.go new file mode 100644 index 00000000..48b54ec8 --- /dev/null +++ b/pkg/rewards/operator_split.go @@ -0,0 +1,170 @@ +package rewards + +import ( + "errors" + "sort" + + "github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common" + "github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common/flags" + "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/logging" + eigenSdkUtils "github.com/Layr-Labs/eigensdk-go/utils" + gethcommon "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/ethclient" + "github.com/urfave/cli/v2" +) + +func OperatorSplitCmd(p utils.Prompter) *cli.Command { + var operatorSplitCmd = &cli.Command{ + Name: "set-operator-split", + Usage: "Set operator split", + Action: func(cCtx *cli.Context) error { + return OperatorSplit(cCtx, p) + }, + After: telemetry.AfterRunAction(), + Flags: getOperatorSplitFlags(), + } + + return operatorSplitCmd +} + +func OperatorSplit(cCtx *cli.Context, p utils.Prompter) error { + ctx := cCtx.Context + logger := common.GetLogger(cCtx) + + config, err := readAndValidateOperatorSplitConfig(cCtx, logger) + if err != nil { + return eigenSdkUtils.WrapError("failed to read and validate claim config", err) + } + + cCtx.App.Metadata["network"] = config.ChainID.String() + + ethClient, err := ethclient.Dial(config.RPCUrl) + if err != nil { + return eigenSdkUtils.WrapError("failed to create new eth client", err) + } + + eLWriter, err := common.GetELWriter( + config.OperatorAddress, + config.SignerConfig, + ethClient, + elcontracts.Config{ + RewardsCoordinatorAddress: config.RewardsCoordinatorAddress, + }, + p, + config.ChainID, + logger, + ) + + if err != nil { + return eigenSdkUtils.WrapError("failed to get EL writer", err) + } + + logger.Infof("Broadcasting set operator transaction...") + + var receipt *types.Receipt + + receipt, err = eLWriter.SetOperatorAVSSplit(ctx, config.OperatorAddress, config.AVSAddress, config.Split, true) + + if err != nil { + return eigenSdkUtils.WrapError("failed to process claim", err) + } + + logger.Infof("Set operator transaction submitted successfully") + common.PrintTransactionInfo(receipt.TxHash.String(), config.ChainID) + + return nil +} + +func readAndValidateOperatorSplitConfig(cCtx *cli.Context, logger logging.Logger) (*SetOperatorAVSSplitConfig, error) { + network := cCtx.String(flags.NetworkFlag.Name) + environment := cCtx.String(EnvironmentFlag.Name) + rpcUrl := cCtx.String(flags.ETHRpcUrlFlag.Name) + broadcast := cCtx.Bool(flags.BroadcastFlag.Name) + split := cCtx.Int(OperatorSplitFlag.Name) + rewardsCoordinatorAddress := cCtx.String(RewardsCoordinatorAddressFlag.Name) + + var err error + if common.IsEmptyString(rewardsCoordinatorAddress) { + rewardsCoordinatorAddress, err = common.GetRewardCoordinatorAddress(utils.NetworkNameToChainId(network)) + if err != nil { + return nil, err + } + } + logger.Debugf("Using Rewards Coordinator address: %s", rewardsCoordinatorAddress) + + claimTimestamp := cCtx.String(ClaimTimestampFlag.Name) + logger.Debugf("Using claim timestamp from user: %s", claimTimestamp) + + operatorAddress := gethcommon.HexToAddress(cCtx.String(OperatorAddressFlag.Name)) + logger.Infof("Using operator address: %s", operatorAddress.String()) + + avsAddress := gethcommon.HexToAddress(cCtx.String(AVSAddressesFlag.Name)) + logger.Infof("Using AVS address: %s", avsAddress.String()) + + chainID := utils.NetworkNameToChainId(network) + logger.Debugf("Using chain ID: %s", chainID.String()) + + proofStoreBaseURL := cCtx.String(ProofStoreBaseURLFlag.Name) + + // If empty get from utils + if common.IsEmptyString(proofStoreBaseURL) { + proofStoreBaseURL = getProofStoreBaseURL(network) + + // If still empty return error + if common.IsEmptyString(proofStoreBaseURL) { + return nil, errors.New("proof store base URL not provided") + } + } + logger.Debugf("Using Proof store base URL: %s", proofStoreBaseURL) + + if common.IsEmptyString(environment) { + environment = getEnvFromNetwork(network) + } + logger.Debugf("Using network %s and environment: %s", network, environment) + + // Get SignerConfig + signerConfig, err := common.GetSignerConfig(cCtx, logger) + if err != nil { + // We don't want to throw error since people can still use it to generate the claim + // without broadcasting it + logger.Debugf("Failed to get signer config: %s", err) + } + + // TODO(shrimalmadhur): Fix to make sure correct S3 bucket is used. Clean up later + if network == utils.MainnetNetworkName { + network = "ethereum" + } + + return &SetOperatorAVSSplitConfig{ + Network: network, + RPCUrl: rpcUrl, + Broadcast: broadcast, + RewardsCoordinatorAddress: gethcommon.HexToAddress(rewardsCoordinatorAddress), + ChainID: chainID, + SignerConfig: signerConfig, + OperatorAddress: operatorAddress, + AVSAddress: avsAddress, + Split: uint16(split), + }, nil +} + +func getOperatorSplitFlags() []cli.Flag { + baseFlags := []cli.Flag{ + &flags.NetworkFlag, + &flags.ETHRpcUrlFlag, + &flags.OutputFileFlag, + &OperatorAddressFlag, + &OperatorSplitFlag, + &RewardsCoordinatorAddressFlag, + &ClaimTimestampFlag, + &AVSAddressesFlag, + } + + allFlags := append(baseFlags, flags.GetSignerFlags()...) + sort.Sort(cli.FlagsByName(allFlags)) + return allFlags +} diff --git a/pkg/rewards/types.go b/pkg/rewards/types.go index 50e88ea6..899254d7 100644 --- a/pkg/rewards/types.go +++ b/pkg/rewards/types.go @@ -15,6 +15,18 @@ type rewardsJson struct { type allRewardsJson []rewardsJson +type SetOperatorAVSSplitConfig struct { + Network string + RPCUrl string + Broadcast bool + RewardsCoordinatorAddress gethcommon.Address + ChainID *big.Int + SignerConfig *types.SignerConfig + + OperatorAddress gethcommon.Address + AVSAddress gethcommon.Address + Split uint16 +} type ClaimConfig struct { Network string RPCUrl string From 6c37622f12adfeaff93829438e1466169de57298 Mon Sep 17 00:00:00 2001 From: gpabst Date: Tue, 10 Dec 2024 12:39:49 -0500 Subject: [PATCH 02/13] feat: add get operator split command --- pkg/rewards.go | 3 +- pkg/rewards/operator_split.go | 63 ++++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/pkg/rewards.go b/pkg/rewards.go index f15467d8..23513581 100644 --- a/pkg/rewards.go +++ b/pkg/rewards.go @@ -14,7 +14,8 @@ func RewardsCmd(p utils.Prompter) *cli.Command { rewards.ClaimCmd(p), rewards.SetClaimerCmd(p), rewards.ShowCmd(p), - rewards.OperatorSplitCmd(p), + rewards.SetOperatorSplitCmd(p), + rewards.GetOperatorSplitCmd(p), }, } diff --git a/pkg/rewards/operator_split.go b/pkg/rewards/operator_split.go index 48b54ec8..69194375 100644 --- a/pkg/rewards/operator_split.go +++ b/pkg/rewards/operator_split.go @@ -17,12 +17,12 @@ import ( "github.com/urfave/cli/v2" ) -func OperatorSplitCmd(p utils.Prompter) *cli.Command { +func SetOperatorSplitCmd(p utils.Prompter) *cli.Command { var operatorSplitCmd = &cli.Command{ Name: "set-operator-split", Usage: "Set operator split", Action: func(cCtx *cli.Context) error { - return OperatorSplit(cCtx, p) + return SetOperatorSplit(cCtx, p) }, After: telemetry.AfterRunAction(), Flags: getOperatorSplitFlags(), @@ -31,13 +31,68 @@ func OperatorSplitCmd(p utils.Prompter) *cli.Command { return operatorSplitCmd } -func OperatorSplit(cCtx *cli.Context, p utils.Prompter) error { +func GetOperatorSplitCmd(p utils.Prompter) *cli.Command { + var operatorSplitCmd = &cli.Command{ + Name: "get-operator-split", + Usage: "Get operator split", + Action: func(cCtx *cli.Context) error { + return GetOperatorSplit(cCtx, p) + }, + After: telemetry.AfterRunAction(), + Flags: getOperatorSplitFlags(), + } + + return operatorSplitCmd +} + +func GetOperatorSplit(cCtx *cli.Context, p utils.Prompter) error { + ctx := cCtx.Context + logger := common.GetLogger(cCtx) + + config, err := readAndValidateOperatorSplitConfig(cCtx, logger) + if err != nil { + return eigenSdkUtils.WrapError("failed to read and validate operator split config", err) + } + + cCtx.App.Metadata["network"] = config.ChainID.String() + + ethClient, err := ethclient.Dial(config.RPCUrl) + if err != nil { + return eigenSdkUtils.WrapError("failed to create new eth client", err) + } + + elReader, err := elcontracts.NewReaderFromConfig( + elcontracts.Config{ + RewardsCoordinatorAddress: config.RewardsCoordinatorAddress, + }, + ethClient, + logger, + ) + + if err != nil { + return eigenSdkUtils.WrapError("failed to get EL writer", err) + } + + logger.Infof("Getting operator split...") + + split, err := elReader.GetOperatorAVSSplit(ctx, config.OperatorAddress, config.AVSAddress) + + if err != nil || split == nil { + return eigenSdkUtils.WrapError("failed to get operator split", err) + } + + logger.Infof("Operator split is %d", *split) + + return nil +} + +func SetOperatorSplit(cCtx *cli.Context, p utils.Prompter) error { ctx := cCtx.Context logger := common.GetLogger(cCtx) config, err := readAndValidateOperatorSplitConfig(cCtx, logger) if err != nil { - return eigenSdkUtils.WrapError("failed to read and validate claim config", err) + return eigenSdkUtils.WrapError("failed to read and validate operator split config", err) } cCtx.App.Metadata["network"] = config.ChainID.String() From 8bbc03276365b6893629f8d0487a3ac8c950f9f4 Mon Sep 17 00:00:00 2001 From: gpabst Date: Wed, 11 Dec 2024 11:21:39 -0500 Subject: [PATCH 03/13] chore: update to reflect that split is in bips --- pkg/rewards/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/rewards/flags.go b/pkg/rewards/flags.go index fabc1e49..657f7fdf 100644 --- a/pkg/rewards/flags.go +++ b/pkg/rewards/flags.go @@ -103,7 +103,7 @@ var ( OperatorSplitFlag = cli.IntFlag{ Name: "operator-split", Aliases: []string{"os"}, - Usage: "Split for the operator", + Usage: "Split for the operator in bips (e.g. 1000 = 10%)", Required: false, EnvVars: []string{"REWARDS_OPERATOR_SPLIT"}, } From 789ece326252987e06a317af3c4ead7427965744 Mon Sep 17 00:00:00 2001 From: gpabst Date: Wed, 11 Dec 2024 17:22:48 -0500 Subject: [PATCH 04/13] refactor: move command into operator sub-commands --- pkg/internal/common/flags/general.go | 7 + pkg/operator.go | 2 + pkg/operator/get_operator_split.go | 105 +++++++++++++ .../set_operator_split.go} | 142 ++++-------------- pkg/operator/split/flags.go | 20 +++ pkg/operator/split/types.go | 30 ++++ pkg/rewards.go | 2 - pkg/rewards/claim.go | 1 + pkg/rewards/flags.go | 16 -- pkg/rewards/types.go | 12 -- 10 files changed, 194 insertions(+), 143 deletions(-) create mode 100644 pkg/operator/get_operator_split.go rename pkg/{rewards/operator_split.go => operator/set_operator_split.go} (53%) create mode 100644 pkg/operator/split/flags.go create mode 100644 pkg/operator/split/types.go diff --git a/pkg/internal/common/flags/general.go b/pkg/internal/common/flags/general.go index 2ae9378c..4077c1a5 100644 --- a/pkg/internal/common/flags/general.go +++ b/pkg/internal/common/flags/general.go @@ -91,6 +91,13 @@ var ( Value: 3600, } + OperatorAddressFlag = cli.StringFlag{ + Name: "operator-address", + Aliases: []string{"oa", "operator"}, + Usage: "Operator address", + EnvVars: []string{"OPERATOR_ADDRESS"}, + } + BatchClaimFile = cli.StringFlag{ Name: "batch-claim-file", Aliases: []string{"bcf"}, diff --git a/pkg/operator.go b/pkg/operator.go index f3ca2ce4..7458852f 100644 --- a/pkg/operator.go +++ b/pkg/operator.go @@ -18,6 +18,8 @@ func OperatorCmd(p utils.Prompter) *cli.Command { operator.UpdateCmd(p), operator.UpdateMetadataURICmd(p), operator.GetApprovalCmd(p), + operator.SetOperatorSplitCmd(p), + operator.GetOperatorSplitCmd(p), }, } diff --git a/pkg/operator/get_operator_split.go b/pkg/operator/get_operator_split.go new file mode 100644 index 00000000..05c288ce --- /dev/null +++ b/pkg/operator/get_operator_split.go @@ -0,0 +1,105 @@ +package operator + +import ( + "github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common" + "github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common/flags" + "github.com/Layr-Labs/eigenlayer-cli/pkg/operator/split" + "github.com/Layr-Labs/eigenlayer-cli/pkg/rewards" + "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/logging" + eigenSdkUtils "github.com/Layr-Labs/eigensdk-go/utils" + gethcommon "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" + "github.com/urfave/cli/v2" +) + +func GetOperatorSplitCmd(p utils.Prompter) *cli.Command { + var operatorSplitCmd = &cli.Command{ + Name: "get-rewards-split", + Usage: "Get operator rewards split", + Action: func(cCtx *cli.Context) error { + return GetOperatorSplit(cCtx, p) + }, + After: telemetry.AfterRunAction(), + Flags: getOperatorSplitFlags(), + } + + return operatorSplitCmd +} + +func GetOperatorSplit(cCtx *cli.Context, p utils.Prompter) error { + ctx := cCtx.Context + logger := common.GetLogger(cCtx) + + config, err := readAndValidateGetOperatorSplitConfig(cCtx, logger) + if err != nil { + return eigenSdkUtils.WrapError("failed to read and validate operator split config", err) + } + + cCtx.App.Metadata["network"] = config.ChainID.String() + + ethClient, err := ethclient.Dial(config.RPCUrl) + if err != nil { + return eigenSdkUtils.WrapError("failed to create new eth client", err) + } + + elReader, err := elcontracts.NewReaderFromConfig( + elcontracts.Config{ + RewardsCoordinatorAddress: config.RewardsCoordinatorAddress, + }, + ethClient, + logger, + ) + + if err != nil { + return eigenSdkUtils.WrapError("failed to get EL writer", err) + } + + logger.Infof("Getting operator split...") + + split, err := elReader.GetOperatorAVSSplit(ctx, config.OperatorAddress, config.AVSAddress) + + if err != nil || split == nil { + return eigenSdkUtils.WrapError("failed to get operator split", err) + } + + logger.Infof("Operator split is %d", *split) + + return nil +} + +func readAndValidateGetOperatorSplitConfig(cCtx *cli.Context, logger logging.Logger) (*split.GetOperatorAVSSplitConfig, error) { + network := cCtx.String(flags.NetworkFlag.Name) + rpcUrl := cCtx.String(flags.ETHRpcUrlFlag.Name) + + rewardsCoordinatorAddress := cCtx.String(rewards.RewardsCoordinatorAddressFlag.Name) + + var err error + if common.IsEmptyString(rewardsCoordinatorAddress) { + rewardsCoordinatorAddress, err = common.GetRewardCoordinatorAddress(utils.NetworkNameToChainId(network)) + if err != nil { + return nil, err + } + } + logger.Debugf("Using Rewards Coordinator address: %s", rewardsCoordinatorAddress) + + operatorAddress := gethcommon.HexToAddress(cCtx.String(flags.OperatorAddressFlag.Name)) + logger.Infof("Using operator address: %s", operatorAddress.String()) + + avsAddress := gethcommon.HexToAddress(cCtx.String(split.AVSAddressFlag.Name)) + logger.Infof("Using AVS address: %s", avsAddress.String()) + + chainID := utils.NetworkNameToChainId(network) + logger.Debugf("Using chain ID: %s", chainID.String()) + + return &split.GetOperatorAVSSplitConfig{ + Network: network, + RPCUrl: rpcUrl, + RewardsCoordinatorAddress: gethcommon.HexToAddress(rewardsCoordinatorAddress), + ChainID: chainID, + OperatorAddress: operatorAddress, + AVSAddress: avsAddress, + }, nil +} diff --git a/pkg/rewards/operator_split.go b/pkg/operator/set_operator_split.go similarity index 53% rename from pkg/rewards/operator_split.go rename to pkg/operator/set_operator_split.go index 69194375..59b83779 100644 --- a/pkg/rewards/operator_split.go +++ b/pkg/operator/set_operator_split.go @@ -1,11 +1,12 @@ -package rewards +package operator import ( - "errors" "sort" "github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common" "github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common/flags" + "github.com/Layr-Labs/eigenlayer-cli/pkg/operator/split" + "github.com/Layr-Labs/eigenlayer-cli/pkg/rewards" "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" @@ -19,8 +20,8 @@ import ( func SetOperatorSplitCmd(p utils.Prompter) *cli.Command { var operatorSplitCmd = &cli.Command{ - Name: "set-operator-split", - Usage: "Set operator split", + Name: "set-rewards-split", + Usage: "Set operator rewards split", Action: func(cCtx *cli.Context) error { return SetOperatorSplit(cCtx, p) }, @@ -31,66 +32,11 @@ func SetOperatorSplitCmd(p utils.Prompter) *cli.Command { return operatorSplitCmd } -func GetOperatorSplitCmd(p utils.Prompter) *cli.Command { - var operatorSplitCmd = &cli.Command{ - Name: "get-operator-split", - Usage: "Get operator split", - Action: func(cCtx *cli.Context) error { - return GetOperatorSplit(cCtx, p) - }, - After: telemetry.AfterRunAction(), - Flags: getOperatorSplitFlags(), - } - - return operatorSplitCmd -} - -func GetOperatorSplit(cCtx *cli.Context, p utils.Prompter) error { - ctx := cCtx.Context - logger := common.GetLogger(cCtx) - - config, err := readAndValidateOperatorSplitConfig(cCtx, logger) - if err != nil { - return eigenSdkUtils.WrapError("failed to read and validate operator split config", err) - } - - cCtx.App.Metadata["network"] = config.ChainID.String() - - ethClient, err := ethclient.Dial(config.RPCUrl) - if err != nil { - return eigenSdkUtils.WrapError("failed to create new eth client", err) - } - - elReader, err := elcontracts.NewReaderFromConfig( - elcontracts.Config{ - RewardsCoordinatorAddress: config.RewardsCoordinatorAddress, - }, - ethClient, - logger, - ) - - if err != nil { - return eigenSdkUtils.WrapError("failed to get EL writer", err) - } - - logger.Infof("Getting operator split...") - - split, err := elReader.GetOperatorAVSSplit(ctx, config.OperatorAddress, config.AVSAddress) - - if err != nil || split == nil { - return eigenSdkUtils.WrapError("failed to get operator split", err) - } - - logger.Infof("Operator split is %d", *split) - - return nil -} - func SetOperatorSplit(cCtx *cli.Context, p utils.Prompter) error { ctx := cCtx.Context logger := common.GetLogger(cCtx) - config, err := readAndValidateOperatorSplitConfig(cCtx, logger) + config, err := readAndValidateSetOperatorSplitConfig(cCtx, logger) if err != nil { return eigenSdkUtils.WrapError("failed to read and validate operator split config", err) } @@ -134,13 +80,27 @@ func SetOperatorSplit(cCtx *cli.Context, p utils.Prompter) error { return nil } -func readAndValidateOperatorSplitConfig(cCtx *cli.Context, logger logging.Logger) (*SetOperatorAVSSplitConfig, error) { +func getOperatorSplitFlags() []cli.Flag { + baseFlags := []cli.Flag{ + &flags.NetworkFlag, + &flags.ETHRpcUrlFlag, + &flags.OutputFileFlag, + &flags.OperatorAddressFlag, + &split.OperatorSplitFlag, + &rewards.RewardsCoordinatorAddressFlag, + &split.AVSAddressFlag, + } + + allFlags := append(baseFlags, flags.GetSignerFlags()...) + sort.Sort(cli.FlagsByName(allFlags)) + return allFlags +} + +func readAndValidateSetOperatorSplitConfig(cCtx *cli.Context, logger logging.Logger) (*split.SetOperatorAVSSplitConfig, error) { network := cCtx.String(flags.NetworkFlag.Name) - environment := cCtx.String(EnvironmentFlag.Name) rpcUrl := cCtx.String(flags.ETHRpcUrlFlag.Name) - broadcast := cCtx.Bool(flags.BroadcastFlag.Name) - split := cCtx.Int(OperatorSplitFlag.Name) - rewardsCoordinatorAddress := cCtx.String(RewardsCoordinatorAddressFlag.Name) + opSplit := cCtx.Int(split.OperatorSplitFlag.Name) + rewardsCoordinatorAddress := cCtx.String(rewards.RewardsCoordinatorAddressFlag.Name) var err error if common.IsEmptyString(rewardsCoordinatorAddress) { @@ -151,36 +111,15 @@ func readAndValidateOperatorSplitConfig(cCtx *cli.Context, logger logging.Logger } logger.Debugf("Using Rewards Coordinator address: %s", rewardsCoordinatorAddress) - claimTimestamp := cCtx.String(ClaimTimestampFlag.Name) - logger.Debugf("Using claim timestamp from user: %s", claimTimestamp) - - operatorAddress := gethcommon.HexToAddress(cCtx.String(OperatorAddressFlag.Name)) + operatorAddress := gethcommon.HexToAddress(cCtx.String(flags.OperatorAddressFlag.Name)) logger.Infof("Using operator address: %s", operatorAddress.String()) - avsAddress := gethcommon.HexToAddress(cCtx.String(AVSAddressesFlag.Name)) + avsAddress := gethcommon.HexToAddress(cCtx.String(split.AVSAddressFlag.Name)) logger.Infof("Using AVS address: %s", avsAddress.String()) chainID := utils.NetworkNameToChainId(network) logger.Debugf("Using chain ID: %s", chainID.String()) - proofStoreBaseURL := cCtx.String(ProofStoreBaseURLFlag.Name) - - // If empty get from utils - if common.IsEmptyString(proofStoreBaseURL) { - proofStoreBaseURL = getProofStoreBaseURL(network) - - // If still empty return error - if common.IsEmptyString(proofStoreBaseURL) { - return nil, errors.New("proof store base URL not provided") - } - } - logger.Debugf("Using Proof store base URL: %s", proofStoreBaseURL) - - if common.IsEmptyString(environment) { - environment = getEnvFromNetwork(network) - } - logger.Debugf("Using network %s and environment: %s", network, environment) - // Get SignerConfig signerConfig, err := common.GetSignerConfig(cCtx, logger) if err != nil { @@ -189,37 +128,14 @@ func readAndValidateOperatorSplitConfig(cCtx *cli.Context, logger logging.Logger logger.Debugf("Failed to get signer config: %s", err) } - // TODO(shrimalmadhur): Fix to make sure correct S3 bucket is used. Clean up later - if network == utils.MainnetNetworkName { - network = "ethereum" - } - - return &SetOperatorAVSSplitConfig{ + return &split.SetOperatorAVSSplitConfig{ Network: network, RPCUrl: rpcUrl, - Broadcast: broadcast, RewardsCoordinatorAddress: gethcommon.HexToAddress(rewardsCoordinatorAddress), ChainID: chainID, SignerConfig: signerConfig, OperatorAddress: operatorAddress, AVSAddress: avsAddress, - Split: uint16(split), + Split: uint16(opSplit), }, nil } - -func getOperatorSplitFlags() []cli.Flag { - baseFlags := []cli.Flag{ - &flags.NetworkFlag, - &flags.ETHRpcUrlFlag, - &flags.OutputFileFlag, - &OperatorAddressFlag, - &OperatorSplitFlag, - &RewardsCoordinatorAddressFlag, - &ClaimTimestampFlag, - &AVSAddressesFlag, - } - - allFlags := append(baseFlags, flags.GetSignerFlags()...) - sort.Sort(cli.FlagsByName(allFlags)) - return allFlags -} diff --git a/pkg/operator/split/flags.go b/pkg/operator/split/flags.go new file mode 100644 index 00000000..c8ec6bcf --- /dev/null +++ b/pkg/operator/split/flags.go @@ -0,0 +1,20 @@ +package split + +import "github.com/urfave/cli/v2" + +var ( + OperatorSplitFlag = cli.IntFlag{ + Name: "operator-split", + Aliases: []string{"os"}, + Usage: "Split for the operator in bips (e.g. 1000 = 10%)", + Required: false, + EnvVars: []string{"OPERATOR_SPLIT"}, + } + + AVSAddressFlag = cli.StringFlag{ + Name: "avs-address", + Aliases: []string{"aa"}, + Usage: "AVS address to set operator split", + EnvVars: []string{"AVS_ADDRESS"}, + } +) diff --git a/pkg/operator/split/types.go b/pkg/operator/split/types.go new file mode 100644 index 00000000..271a325d --- /dev/null +++ b/pkg/operator/split/types.go @@ -0,0 +1,30 @@ +package split + +import ( + "math/big" + + "github.com/Layr-Labs/eigenlayer-cli/pkg/types" + gethcommon "github.com/ethereum/go-ethereum/common" +) + +type SetOperatorAVSSplitConfig struct { + Network string + RPCUrl string + RewardsCoordinatorAddress gethcommon.Address + ChainID *big.Int + SignerConfig *types.SignerConfig + + OperatorAddress gethcommon.Address + AVSAddress gethcommon.Address + Split uint16 +} + +type GetOperatorAVSSplitConfig struct { + Network string + RPCUrl string + RewardsCoordinatorAddress gethcommon.Address + ChainID *big.Int + + OperatorAddress gethcommon.Address + AVSAddress gethcommon.Address +} diff --git a/pkg/rewards.go b/pkg/rewards.go index 23513581..81828aa3 100644 --- a/pkg/rewards.go +++ b/pkg/rewards.go @@ -14,8 +14,6 @@ func RewardsCmd(p utils.Prompter) *cli.Command { rewards.ClaimCmd(p), rewards.SetClaimerCmd(p), rewards.ShowCmd(p), - rewards.SetOperatorSplitCmd(p), - rewards.GetOperatorSplitCmd(p), }, } diff --git a/pkg/rewards/claim.go b/pkg/rewards/claim.go index fb078fca..e302809c 100644 --- a/pkg/rewards/claim.go +++ b/pkg/rewards/claim.go @@ -278,6 +278,7 @@ func Claim(cCtx *cli.Context, p utils.Prompter) error { elClaims := []rewardscoordinator.IRewardsCoordinatorRewardsMerkleClaim{*elClaim} claims := []contractrewardscoordinator.IRewardsCoordinatorRewardsMerkleClaim{*claim} accounts := []merkletree.MerkleTree{*account} + err = broadcastClaims(config, ethClient, logger, p, ctx, elClaims, claims, accounts) return err diff --git a/pkg/rewards/flags.go b/pkg/rewards/flags.go index 657f7fdf..5cc25b32 100644 --- a/pkg/rewards/flags.go +++ b/pkg/rewards/flags.go @@ -91,20 +91,4 @@ var ( Value: "all", EnvVars: []string{"REWARDS_CLAIM_TYPE"}, } - - OperatorAddressFlag = cli.StringFlag{ - Name: "operator-address", - Aliases: []string{"a"}, - Usage: "Address of the operator", - Required: false, - EnvVars: []string{"REWARDS_OPERATOR_ADDRESS"}, - } - - OperatorSplitFlag = cli.IntFlag{ - Name: "operator-split", - Aliases: []string{"os"}, - Usage: "Split for the operator in bips (e.g. 1000 = 10%)", - Required: false, - EnvVars: []string{"REWARDS_OPERATOR_SPLIT"}, - } ) diff --git a/pkg/rewards/types.go b/pkg/rewards/types.go index 899254d7..50e88ea6 100644 --- a/pkg/rewards/types.go +++ b/pkg/rewards/types.go @@ -15,18 +15,6 @@ type rewardsJson struct { type allRewardsJson []rewardsJson -type SetOperatorAVSSplitConfig struct { - Network string - RPCUrl string - Broadcast bool - RewardsCoordinatorAddress gethcommon.Address - ChainID *big.Int - SignerConfig *types.SignerConfig - - OperatorAddress gethcommon.Address - AVSAddress gethcommon.Address - Split uint16 -} type ClaimConfig struct { Network string RPCUrl string From ff8f8cae69a6433e023ada7a582ce8e12897813b Mon Sep 17 00:00:00 2001 From: gpabst Date: Wed, 11 Dec 2024 17:25:07 -0500 Subject: [PATCH 05/13] fix: remove unused flag --- pkg/operator/set_operator_split.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/operator/set_operator_split.go b/pkg/operator/set_operator_split.go index 59b83779..fcbbc25a 100644 --- a/pkg/operator/set_operator_split.go +++ b/pkg/operator/set_operator_split.go @@ -84,7 +84,6 @@ func getOperatorSplitFlags() []cli.Flag { baseFlags := []cli.Flag{ &flags.NetworkFlag, &flags.ETHRpcUrlFlag, - &flags.OutputFileFlag, &flags.OperatorAddressFlag, &split.OperatorSplitFlag, &rewards.RewardsCoordinatorAddressFlag, From 9a5b2642514e686958ae6418a17916b5fdcf9784 Mon Sep 17 00:00:00 2001 From: gpabst Date: Wed, 11 Dec 2024 17:26:26 -0500 Subject: [PATCH 06/13] fix: remove updates to rewards package --- pkg/rewards/claim.go | 1 - pkg/rewards/flags.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/rewards/claim.go b/pkg/rewards/claim.go index e302809c..fb078fca 100644 --- a/pkg/rewards/claim.go +++ b/pkg/rewards/claim.go @@ -278,7 +278,6 @@ func Claim(cCtx *cli.Context, p utils.Prompter) error { elClaims := []rewardscoordinator.IRewardsCoordinatorRewardsMerkleClaim{*elClaim} claims := []contractrewardscoordinator.IRewardsCoordinatorRewardsMerkleClaim{*claim} accounts := []merkletree.MerkleTree{*account} - err = broadcastClaims(config, ethClient, logger, p, ctx, elClaims, claims, accounts) return err diff --git a/pkg/rewards/flags.go b/pkg/rewards/flags.go index 5cc25b32..810b725d 100644 --- a/pkg/rewards/flags.go +++ b/pkg/rewards/flags.go @@ -79,7 +79,7 @@ var ( AVSAddressesFlag = cli.StringFlag{ Name: "avs-addresses", - Aliases: []string{"aa"}, + Aliases: []string{"a"}, Usage: "Comma seperated addresses of the AVS", EnvVars: []string{"AVS_ADDRESSES"}, } From 71071cf700324765691dcb10f1309125da0df4ce Mon Sep 17 00:00:00 2001 From: gpabst Date: Wed, 11 Dec 2024 17:30:36 -0500 Subject: [PATCH 07/13] fix: remove unused param --- pkg/operator/get_operator_split.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/operator/get_operator_split.go b/pkg/operator/get_operator_split.go index 05c288ce..e83459b6 100644 --- a/pkg/operator/get_operator_split.go +++ b/pkg/operator/get_operator_split.go @@ -20,7 +20,7 @@ func GetOperatorSplitCmd(p utils.Prompter) *cli.Command { Name: "get-rewards-split", Usage: "Get operator rewards split", Action: func(cCtx *cli.Context) error { - return GetOperatorSplit(cCtx, p) + return GetOperatorSplit(cCtx) }, After: telemetry.AfterRunAction(), Flags: getOperatorSplitFlags(), @@ -29,7 +29,7 @@ func GetOperatorSplitCmd(p utils.Prompter) *cli.Command { return operatorSplitCmd } -func GetOperatorSplit(cCtx *cli.Context, p utils.Prompter) error { +func GetOperatorSplit(cCtx *cli.Context) error { ctx := cCtx.Context logger := common.GetLogger(cCtx) From 6046a3e414c63c503df322224c408afe69e647bc Mon Sep 17 00:00:00 2001 From: gpabst Date: Wed, 11 Dec 2024 17:31:03 -0500 Subject: [PATCH 08/13] chore: run make fmt --- pkg/operator/get_operator_split.go | 5 ++++- pkg/operator/set_operator_split.go | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/operator/get_operator_split.go b/pkg/operator/get_operator_split.go index e83459b6..075f2331 100644 --- a/pkg/operator/get_operator_split.go +++ b/pkg/operator/get_operator_split.go @@ -70,7 +70,10 @@ func GetOperatorSplit(cCtx *cli.Context) error { return nil } -func readAndValidateGetOperatorSplitConfig(cCtx *cli.Context, logger logging.Logger) (*split.GetOperatorAVSSplitConfig, error) { +func readAndValidateGetOperatorSplitConfig( + cCtx *cli.Context, + logger logging.Logger, +) (*split.GetOperatorAVSSplitConfig, error) { network := cCtx.String(flags.NetworkFlag.Name) rpcUrl := cCtx.String(flags.ETHRpcUrlFlag.Name) diff --git a/pkg/operator/set_operator_split.go b/pkg/operator/set_operator_split.go index fcbbc25a..b6eeea0e 100644 --- a/pkg/operator/set_operator_split.go +++ b/pkg/operator/set_operator_split.go @@ -95,7 +95,10 @@ func getOperatorSplitFlags() []cli.Flag { return allFlags } -func readAndValidateSetOperatorSplitConfig(cCtx *cli.Context, logger logging.Logger) (*split.SetOperatorAVSSplitConfig, error) { +func readAndValidateSetOperatorSplitConfig( + cCtx *cli.Context, + logger logging.Logger, +) (*split.SetOperatorAVSSplitConfig, error) { network := cCtx.String(flags.NetworkFlag.Name) rpcUrl := cCtx.String(flags.ETHRpcUrlFlag.Name) opSplit := cCtx.Int(split.OperatorSplitFlag.Name) From 0d2ed17d5eabce928364e1bfedf8a672a52dfe0b Mon Sep 17 00:00:00 2001 From: gpabst Date: Wed, 11 Dec 2024 19:13:29 -0500 Subject: [PATCH 09/13] fix: remove signer flags from get --- pkg/operator/get_operator_split.go | 18 +++++++++++++++++- pkg/operator/set_operator_split.go | 4 ++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pkg/operator/get_operator_split.go b/pkg/operator/get_operator_split.go index 075f2331..7183d6c1 100644 --- a/pkg/operator/get_operator_split.go +++ b/pkg/operator/get_operator_split.go @@ -1,6 +1,8 @@ package operator import ( + "sort" + "github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common" "github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common/flags" "github.com/Layr-Labs/eigenlayer-cli/pkg/operator/split" @@ -23,12 +25,26 @@ func GetOperatorSplitCmd(p utils.Prompter) *cli.Command { return GetOperatorSplit(cCtx) }, After: telemetry.AfterRunAction(), - Flags: getOperatorSplitFlags(), + Flags: getGetOperatorSplitFlags(), } return operatorSplitCmd } +func getGetOperatorSplitFlags() []cli.Flag { + baseFlags := []cli.Flag{ + &flags.NetworkFlag, + &flags.ETHRpcUrlFlag, + &flags.OperatorAddressFlag, + &split.OperatorSplitFlag, + &rewards.RewardsCoordinatorAddressFlag, + &split.AVSAddressFlag, + } + + sort.Sort(cli.FlagsByName(baseFlags)) + return baseFlags +} + func GetOperatorSplit(cCtx *cli.Context) error { ctx := cCtx.Context logger := common.GetLogger(cCtx) diff --git a/pkg/operator/set_operator_split.go b/pkg/operator/set_operator_split.go index b6eeea0e..3a2f0fb3 100644 --- a/pkg/operator/set_operator_split.go +++ b/pkg/operator/set_operator_split.go @@ -26,7 +26,7 @@ func SetOperatorSplitCmd(p utils.Prompter) *cli.Command { return SetOperatorSplit(cCtx, p) }, After: telemetry.AfterRunAction(), - Flags: getOperatorSplitFlags(), + Flags: getSetOperatorSplitFlags(), } return operatorSplitCmd @@ -80,7 +80,7 @@ func SetOperatorSplit(cCtx *cli.Context, p utils.Prompter) error { return nil } -func getOperatorSplitFlags() []cli.Flag { +func getSetOperatorSplitFlags() []cli.Flag { baseFlags := []cli.Flag{ &flags.NetworkFlag, &flags.ETHRpcUrlFlag, From c7f49128a3698bf243f07362c18d70ecacd636fc Mon Sep 17 00:00:00 2001 From: gpabst Date: Thu, 12 Dec 2024 09:38:15 -0500 Subject: [PATCH 10/13] feat: support outputting call data and output flags --- pkg/operator/set_operator_split.go | 98 +++++++++++++++++++++++------- pkg/operator/split/types.go | 10 +-- 2 files changed, 82 insertions(+), 26 deletions(-) diff --git a/pkg/operator/set_operator_split.go b/pkg/operator/set_operator_split.go index 3a2f0fb3..8fefd085 100644 --- a/pkg/operator/set_operator_split.go +++ b/pkg/operator/set_operator_split.go @@ -1,6 +1,7 @@ package operator import ( + "fmt" "sort" "github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common" @@ -48,35 +49,78 @@ func SetOperatorSplit(cCtx *cli.Context, p utils.Prompter) error { return eigenSdkUtils.WrapError("failed to create new eth client", err) } - eLWriter, err := common.GetELWriter( - config.OperatorAddress, - config.SignerConfig, - ethClient, - elcontracts.Config{ - RewardsCoordinatorAddress: config.RewardsCoordinatorAddress, - }, - p, - config.ChainID, - logger, - ) + if config.Broadcast { - if err != nil { - return eigenSdkUtils.WrapError("failed to get EL writer", err) - } + eLWriter, err := common.GetELWriter( + config.OperatorAddress, + config.SignerConfig, + ethClient, + elcontracts.Config{ + RewardsCoordinatorAddress: config.RewardsCoordinatorAddress, + }, + p, + config.ChainID, + logger, + ) + + if err != nil { + return eigenSdkUtils.WrapError("failed to get EL writer", err) + } - logger.Infof("Broadcasting set operator transaction...") + logger.Infof("Broadcasting set operator transaction...") - var receipt *types.Receipt + var receipt *types.Receipt - receipt, err = eLWriter.SetOperatorAVSSplit(ctx, config.OperatorAddress, config.AVSAddress, config.Split, true) + receipt, err = eLWriter.SetOperatorAVSSplit(ctx, config.OperatorAddress, config.AVSAddress, config.Split, true) - if err != nil { - return eigenSdkUtils.WrapError("failed to process claim", err) - } + if err != nil { + return eigenSdkUtils.WrapError("failed to process claim", err) + } + + logger.Infof("Set operator transaction submitted successfully") + common.PrintTransactionInfo(receipt.TxHash.String(), config.ChainID) + } else { + noSendTxOpts := common.GetNoSendTxOpts(config.OperatorAddress) + _, _, contractBindings, err := elcontracts.BuildClients(elcontracts.Config{ + RewardsCoordinatorAddress: config.RewardsCoordinatorAddress, + }, ethClient, nil, logger, nil) + if err != nil { + return err + } + + code, err := ethClient.CodeAt(ctx, config.OperatorAddress, nil) + if err != nil { + return eigenSdkUtils.WrapError("failed to get code at address", err) + } + if len(code) > 0 { + // Claimer is a smart contract + noSendTxOpts.GasLimit = 150_000 + } + var unsignedTx *types.Transaction + unsignedTx, err = contractBindings.RewardsCoordinator.SetOperatorAVSSplit(noSendTxOpts, config.OperatorAddress, config.AVSAddress, config.Split) - logger.Infof("Set operator transaction submitted successfully") - common.PrintTransactionInfo(receipt.TxHash.String(), config.ChainID) + if err != nil { + return eigenSdkUtils.WrapError("failed to create unsigned tx", err) + } + if config.OutputType == string(common.OutputType_Calldata) { + calldataHex := gethcommon.Bytes2Hex(unsignedTx.Data()) + + if !common.IsEmptyString(config.OutputFile) { + err = common.WriteToFile([]byte(calldataHex), config.OutputFile) + if err != nil { + return err + } + logger.Infof("Call data written to file: %s", config.OutputFile) + } else { + fmt.Println(calldataHex) + } + } + txFeeDetails := common.GetTxFeeDetails(unsignedTx) + fmt.Println() + txFeeDetails.Print() + fmt.Println("To broadcast the operator set split, use the --broadcast flag") + } return nil } @@ -88,6 +132,9 @@ func getSetOperatorSplitFlags() []cli.Flag { &split.OperatorSplitFlag, &rewards.RewardsCoordinatorAddressFlag, &split.AVSAddressFlag, + &flags.BroadcastFlag, + &flags.OutputTypeFlag, + &flags.OutputFileFlag, } allFlags := append(baseFlags, flags.GetSignerFlags()...) @@ -102,6 +149,10 @@ func readAndValidateSetOperatorSplitConfig( network := cCtx.String(flags.NetworkFlag.Name) rpcUrl := cCtx.String(flags.ETHRpcUrlFlag.Name) opSplit := cCtx.Int(split.OperatorSplitFlag.Name) + broadcast := cCtx.Bool(flags.BroadcastFlag.Name) + outputType := cCtx.String(flags.OutputTypeFlag.Name) + outputFile := cCtx.String(flags.OutputFileFlag.Name) + rewardsCoordinatorAddress := cCtx.String(rewards.RewardsCoordinatorAddressFlag.Name) var err error @@ -139,5 +190,8 @@ func readAndValidateSetOperatorSplitConfig( OperatorAddress: operatorAddress, AVSAddress: avsAddress, Split: uint16(opSplit), + Broadcast: broadcast, + OutputType: outputType, + OutputFile: outputFile, }, nil } diff --git a/pkg/operator/split/types.go b/pkg/operator/split/types.go index 271a325d..0daf2c25 100644 --- a/pkg/operator/split/types.go +++ b/pkg/operator/split/types.go @@ -13,10 +13,12 @@ type SetOperatorAVSSplitConfig struct { RewardsCoordinatorAddress gethcommon.Address ChainID *big.Int SignerConfig *types.SignerConfig - - OperatorAddress gethcommon.Address - AVSAddress gethcommon.Address - Split uint16 + Broadcast bool + OperatorAddress gethcommon.Address + AVSAddress gethcommon.Address + Split uint16 + OutputType string + OutputFile string } type GetOperatorAVSSplitConfig struct { From f0f74a1d638518a3b10a49c47ab9f500aed8b9f1 Mon Sep 17 00:00:00 2001 From: gpabst Date: Thu, 12 Dec 2024 10:23:13 -0500 Subject: [PATCH 11/13] chore: use latest eigensdk --- go.mod | 2 +- go.sum | 4 ++-- pkg/operator/get_operator_split.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 98d17d82..1cf783d0 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/Layr-Labs/eigenlayer-contracts v0.3.2-mainnet-rewards github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.12 github.com/Layr-Labs/eigenpod-proofs-generation v0.0.14-stable.0.20240730152248-5c11a259293e - github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241209163655-6b1cbb153ef6 + github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241211225219-79336bf6e886 github.com/blang/semver/v4 v4.0.0 github.com/consensys/gnark-crypto v0.12.1 github.com/ethereum/go-ethereum v1.14.5 diff --git a/go.sum b/go.sum index fcf1f24f..7d2d824e 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,8 @@ github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.12 h1:G5Q1SnLmFbEjhOkky3vIHk github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.12/go.mod h1:OlJd1QjqEW53wfWG/lJyPCGvrXwWVEjPQsP4TV+gttQ= github.com/Layr-Labs/eigenpod-proofs-generation v0.0.14-stable.0.20240730152248-5c11a259293e h1:DvW0/kWHV9mZsbH2KOjEHKTSIONNPUj6X05FJvUohy4= github.com/Layr-Labs/eigenpod-proofs-generation v0.0.14-stable.0.20240730152248-5c11a259293e/go.mod h1:T7tYN8bTdca2pkMnz9G2+ZwXYWw5gWqQUIu4KLgC/vM= -github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241209163655-6b1cbb153ef6 h1:qQk3QJ+I+ffHOpZvaEC1NULxl3Hfzi+ojpniBAmUdWg= -github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241209163655-6b1cbb153ef6/go.mod h1:aYdNURUhaqeYOS+Cq12TfSdPbjFfiLaHkxPdR4Exq/s= +github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241211225219-79336bf6e886 h1:+7AijqdfRXdDc3zvj02Alqsk6Qd3owvlqPYQN1Hc1ME= +github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241211225219-79336bf6e886/go.mod h1:aYdNURUhaqeYOS+Cq12TfSdPbjFfiLaHkxPdR4Exq/s= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8= diff --git a/pkg/operator/get_operator_split.go b/pkg/operator/get_operator_split.go index 7183d6c1..b9571474 100644 --- a/pkg/operator/get_operator_split.go +++ b/pkg/operator/get_operator_split.go @@ -77,11 +77,11 @@ func GetOperatorSplit(cCtx *cli.Context) error { split, err := elReader.GetOperatorAVSSplit(ctx, config.OperatorAddress, config.AVSAddress) - if err != nil || split == nil { + if err != nil { return eigenSdkUtils.WrapError("failed to get operator split", err) } - logger.Infof("Operator split is %d", *split) + logger.Infof("Operator split is %d", split) return nil } From e44298d953471cc12d4fe8ea7a1f6b55113fc7fd Mon Sep 17 00:00:00 2001 From: gpabst Date: Thu, 12 Dec 2024 12:59:40 -0500 Subject: [PATCH 12/13] feat: add features to non-broadcast and isSilent --- pkg/operator/set_operator_split.go | 25 +++++++++++++++---------- pkg/operator/split/types.go | 1 + 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/pkg/operator/set_operator_split.go b/pkg/operator/set_operator_split.go index 8fefd085..aae9b906 100644 --- a/pkg/operator/set_operator_split.go +++ b/pkg/operator/set_operator_split.go @@ -14,7 +14,6 @@ import ( "github.com/Layr-Labs/eigensdk-go/logging" eigenSdkUtils "github.com/Layr-Labs/eigensdk-go/utils" gethcommon "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethclient" "github.com/urfave/cli/v2" ) @@ -69,9 +68,7 @@ func SetOperatorSplit(cCtx *cli.Context, p utils.Prompter) error { logger.Infof("Broadcasting set operator transaction...") - var receipt *types.Receipt - - receipt, err = eLWriter.SetOperatorAVSSplit(ctx, config.OperatorAddress, config.AVSAddress, config.Split, true) + receipt, err := eLWriter.SetOperatorAVSSplit(ctx, config.OperatorAddress, config.AVSAddress, config.Split, true) if err != nil { return eigenSdkUtils.WrapError("failed to process claim", err) @@ -93,11 +90,11 @@ func SetOperatorSplit(cCtx *cli.Context, p utils.Prompter) error { return eigenSdkUtils.WrapError("failed to get code at address", err) } if len(code) > 0 { - // Claimer is a smart contract + // Operator is a smart contract noSendTxOpts.GasLimit = 150_000 } - var unsignedTx *types.Transaction - unsignedTx, err = contractBindings.RewardsCoordinator.SetOperatorAVSSplit(noSendTxOpts, config.OperatorAddress, config.AVSAddress, config.Split) + + unsignedTx, err := contractBindings.RewardsCoordinator.SetOperatorAVSSplit(noSendTxOpts, config.OperatorAddress, config.AVSAddress, config.Split) if err != nil { return eigenSdkUtils.WrapError("failed to create unsigned tx", err) @@ -114,10 +111,15 @@ func SetOperatorSplit(cCtx *cli.Context, p utils.Prompter) error { } else { fmt.Println(calldataHex) } + } else { + logger.Infof("This transaction would set the operator split to %d", config.Split) + } + + if !config.IsSilent { + txFeeDetails := common.GetTxFeeDetails(unsignedTx) + fmt.Println() + txFeeDetails.Print() } - txFeeDetails := common.GetTxFeeDetails(unsignedTx) - fmt.Println() - txFeeDetails.Print() fmt.Println("To broadcast the operator set split, use the --broadcast flag") } @@ -135,6 +137,7 @@ func getSetOperatorSplitFlags() []cli.Flag { &flags.BroadcastFlag, &flags.OutputTypeFlag, &flags.OutputFileFlag, + &flags.SilentFlag, } allFlags := append(baseFlags, flags.GetSignerFlags()...) @@ -152,6 +155,7 @@ func readAndValidateSetOperatorSplitConfig( broadcast := cCtx.Bool(flags.BroadcastFlag.Name) outputType := cCtx.String(flags.OutputTypeFlag.Name) outputFile := cCtx.String(flags.OutputFileFlag.Name) + isSilent := cCtx.Bool(flags.SilentFlag.Name) rewardsCoordinatorAddress := cCtx.String(rewards.RewardsCoordinatorAddressFlag.Name) @@ -193,5 +197,6 @@ func readAndValidateSetOperatorSplitConfig( Broadcast: broadcast, OutputType: outputType, OutputFile: outputFile, + IsSilent: isSilent, }, nil } diff --git a/pkg/operator/split/types.go b/pkg/operator/split/types.go index 0daf2c25..fd98bc39 100644 --- a/pkg/operator/split/types.go +++ b/pkg/operator/split/types.go @@ -19,6 +19,7 @@ type SetOperatorAVSSplitConfig struct { Split uint16 OutputType string OutputFile string + IsSilent bool } type GetOperatorAVSSplitConfig struct { From 0fcdc516ad5e9240ac06b3fe7e595a38ba0b9e37 Mon Sep 17 00:00:00 2001 From: gpabst Date: Thu, 12 Dec 2024 13:45:02 -0500 Subject: [PATCH 13/13] fix: don't print broadcast message if isSilent --- pkg/operator/set_operator_split.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/operator/set_operator_split.go b/pkg/operator/set_operator_split.go index aae9b906..3c6c8460 100644 --- a/pkg/operator/set_operator_split.go +++ b/pkg/operator/set_operator_split.go @@ -119,9 +119,9 @@ func SetOperatorSplit(cCtx *cli.Context, p utils.Prompter) error { txFeeDetails := common.GetTxFeeDetails(unsignedTx) fmt.Println() txFeeDetails.Print() - } - fmt.Println("To broadcast the operator set split, use the --broadcast flag") + fmt.Println("To broadcast the operator set split, use the --broadcast flag") + } } return nil }