Skip to content

Commit

Permalink
feat: add get operator split command
Browse files Browse the repository at this point in the history
  • Loading branch information
gpabst committed Dec 10, 2024
1 parent 8207781 commit 6c37622
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pkg/rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
}

Expand Down
63 changes: 59 additions & 4 deletions pkg/rewards/operator_split.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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()
Expand Down

0 comments on commit 6c37622

Please sign in to comment.