Skip to content

Commit 22e2a6a

Browse files
committed
basic show command
1 parent f8cd8dc commit 22e2a6a

File tree

8 files changed

+160
-42
lines changed

8 files changed

+160
-42
lines changed

pkg/operator/allocations/initializedelay.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func initializeDelayAction(cCtx *cli.Context, p utils.Prompter) error {
5151
}
5252

5353
// Temp to test modify Allocations
54-
config.avsDirectoryAddress = gethcommon.HexToAddress("0x8BffE5a668DB26bc5Ce8dC9C0096fB634747b62A")
54+
config.delegationManagerAddress = gethcommon.HexToAddress("0x05e7c29D006a44D9eB1b9ad74FD6ac3bafbfeB04")
5555

5656
if config.broadcast {
5757
confirm, err := p.Confirm(
@@ -69,7 +69,7 @@ func initializeDelayAction(cCtx *cli.Context, p utils.Prompter) error {
6969
config.signerConfig,
7070
ethClient,
7171
elcontracts.Config{
72-
AvsDirectoryAddress: config.avsDirectoryAddress,
72+
DelegationManagerAddress: config.delegationManagerAddress,
7373
},
7474
p,
7575
config.chainID,
@@ -88,7 +88,7 @@ func initializeDelayAction(cCtx *cli.Context, p utils.Prompter) error {
8888
} else {
8989
noSendTxOpts := common.GetNoSendTxOpts(config.operatorAddress)
9090
_, _, contractBindings, err := elcontracts.BuildClients(elcontracts.Config{
91-
AvsDirectoryAddress: config.avsDirectoryAddress,
91+
DelegationManagerAddress: config.delegationManagerAddress,
9292
}, ethClient, nil, logger, nil)
9393
if err != nil {
9494
return err
@@ -186,22 +186,22 @@ func readAndValidateAllocationDelayConfig(c *cli.Context, logger logging.Logger)
186186
logger.Debugf("Failed to get signer config: %s", err)
187187
}
188188

189-
avsDirectoryAddress, err := utils.GetAVSDirectoryAddress(chainID)
189+
delegationManagerAddress, err := utils.GetDelegationManagerAddress(chainID)
190190
if err != nil {
191191
return nil, err
192192
}
193193

194194
return &allocationDelayConfig{
195-
network: network,
196-
rpcUrl: rpcUrl,
197-
environment: environment,
198-
chainID: chainID,
199-
output: output,
200-
outputType: outputType,
201-
broadcast: broadcast,
202-
operatorAddress: gethcommon.HexToAddress(operatorAddress),
203-
signerConfig: signerConfig,
204-
avsDirectoryAddress: gethcommon.HexToAddress(avsDirectoryAddress),
205-
allocationDelay: uint32(allocationDelayInt),
195+
network: network,
196+
rpcUrl: rpcUrl,
197+
environment: environment,
198+
chainID: chainID,
199+
output: output,
200+
outputType: outputType,
201+
broadcast: broadcast,
202+
operatorAddress: gethcommon.HexToAddress(operatorAddress),
203+
signerConfig: signerConfig,
204+
delegationManagerAddress: gethcommon.HexToAddress(delegationManagerAddress),
205+
allocationDelay: uint32(allocationDelayInt),
206206
}, nil
207207
}

pkg/operator/allocations/show.go

+47-8
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
5050
return eigenSdkUtils.WrapError("failed to create new eth client", err)
5151
}
5252

53-
avsDirectoryAddress, err := utils.GetAVSDirectoryAddress(config.chainID)
54-
if err != nil {
55-
return err
56-
}
53+
// TODO(shrimalmadhur): uncomment it before we merge the PR
54+
// avsDirectoryAddress, err := utils.GetAVSDirectoryAddress(config.chainID)
55+
// if err != nil {
56+
// return err
57+
// }
5758

5859
// Temp to test modify allocations
59-
avsDirectoryAddress = "0x8BffE5a668DB26bc5Ce8dC9C0096fB634747b62A"
60+
avsDirectoryAddress := "0x2a9854D331B8142d024E4007fB4A34311c5176cE"
6061

6162
elReader, err := elcontracts.NewReaderFromConfig(
6263
elcontracts.Config{
@@ -71,14 +72,45 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
7172

7273
// for each strategy address, get the allocatable magnitude
7374
for _, strategyAddress := range config.strategyAddresses {
74-
allocatableMagnitude, err := elReader.GetAllocatableMagnitude(&bind.CallOpts{Context: ctx}, strategyAddress, config.operatorAddress)
75+
allocatableMagnitude, err := elReader.GetAllocatableMagnitude(
76+
&bind.CallOpts{Context: ctx},
77+
config.operatorAddress,
78+
strategyAddress,
79+
)
7580
if err != nil {
7681
return eigenSdkUtils.WrapError("failed to get allocatable magnitude", err)
7782
}
78-
logger.Debug("Allocatable magnitude for strategy", strategyAddress, ":", allocatableMagnitude)
83+
logger.Debugf("Allocatable magnitude for strategy %v: %d", strategyAddress, allocatableMagnitude)
84+
}
85+
86+
opSet, slashableMagnitudes, err := elReader.GetCurrentSlashableMagnitudes(
87+
&bind.CallOpts{Context: ctx},
88+
config.operatorAddress,
89+
config.strategyAddresses,
90+
)
91+
if err != nil {
92+
return eigenSdkUtils.WrapError("failed to get slashable magnitude", err)
93+
}
94+
95+
slashableMagnitudeHolders := make(SlashableMagnitudeHolders, 0)
96+
for i, strategyAddress := range config.strategyAddresses {
97+
slashableMagnitude := slashableMagnitudes[i]
98+
for j, opSet := range opSet {
99+
slashableMagnitudeHolders = append(slashableMagnitudeHolders, SlashableMagnitudesHolder{
100+
StrategyAddress: strategyAddress,
101+
AVSAddress: opSet.Avs,
102+
OperatorSetId: opSet.OperatorSetId,
103+
SlashableMagnitude: slashableMagnitude[j],
104+
})
105+
}
106+
}
107+
108+
if config.outputType == string(common.OutputType_Json) {
109+
slashableMagnitudeHolders.PrintJSON()
110+
} else {
111+
slashableMagnitudeHolders.PrintPretty()
79112
}
80113

81-
82114
return nil
83115
}
84116

@@ -89,6 +121,8 @@ func readAndValidateShowConfig(cCtx *cli.Context, logger *logging.Logger) (*show
89121
operatorAddress := gethcommon.HexToAddress(cCtx.String(flags.OperatorAddressFlag.Name))
90122
avsAddresses := common.ConvertStringSliceToGethAddressSlice(cCtx.StringSlice(flags.AVSAddressesFlag.Name))
91123
strategyAddresses := common.ConvertStringSliceToGethAddressSlice(cCtx.StringSlice(flags.StrategyAddressesFlag.Name))
124+
outputFile := cCtx.String(flags.OutputFileFlag.Name)
125+
outputType := cCtx.String(flags.OutputTypeFlag.Name)
92126

93127
return &showConfig{
94128
network: network,
@@ -97,6 +131,8 @@ func readAndValidateShowConfig(cCtx *cli.Context, logger *logging.Logger) (*show
97131
operatorAddress: operatorAddress,
98132
avsAddresses: avsAddresses,
99133
strategyAddresses: strategyAddresses,
134+
output: outputFile,
135+
outputType: outputType,
100136
}, nil
101137
}
102138

@@ -108,6 +144,9 @@ func getShowFlags() []cli.Flag {
108144
&flags.NetworkFlag,
109145
&flags.EnvironmentFlag,
110146
&flags.ETHRpcUrlFlag,
147+
&flags.VerboseFlag,
148+
&flags.OutputFileFlag,
149+
&flags.OutputTypeFlag,
111150
}
112151

113152
sort.Sort(cli.FlagsByName(baseFlags))

pkg/operator/allocations/types.go

+70-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package allocations
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"math/big"
7+
"strings"
68

79
"github.com/Layr-Labs/eigenlayer-cli/pkg/types"
810

@@ -61,17 +63,17 @@ type allocation struct {
6163
}
6264

6365
type allocationDelayConfig struct {
64-
network string
65-
rpcUrl string
66-
environment string
67-
chainID *big.Int
68-
output string
69-
outputType string
70-
broadcast bool
71-
operatorAddress gethcommon.Address
72-
signerConfig *types.SignerConfig
73-
allocationDelay uint32
74-
avsDirectoryAddress gethcommon.Address
66+
network string
67+
rpcUrl string
68+
environment string
69+
chainID *big.Int
70+
output string
71+
outputType string
72+
broadcast bool
73+
operatorAddress gethcommon.Address
74+
signerConfig *types.SignerConfig
75+
allocationDelay uint32
76+
delegationManagerAddress gethcommon.Address
7577
}
7678

7779
type showConfig struct {
@@ -85,3 +87,60 @@ type showConfig struct {
8587
avsAddresses []gethcommon.Address
8688
strategyAddresses []gethcommon.Address
8789
}
90+
91+
type SlashableMagnitudeHolders []SlashableMagnitudesHolder
92+
93+
type SlashableMagnitudesHolder struct {
94+
StrategyAddress gethcommon.Address
95+
AVSAddress gethcommon.Address
96+
OperatorSetId uint32
97+
SlashableMagnitude uint64
98+
}
99+
100+
func (s SlashableMagnitudeHolders) PrintPretty() {
101+
// Define column headers and widths
102+
headers := []string{"Strategy Address", "AVS Address", "Operator Set ID", "Slashable Magnitude"}
103+
widths := []int{43, 43, 16, 20}
104+
105+
// print dashes
106+
for _, width := range widths {
107+
fmt.Print("+" + strings.Repeat("-", width+1))
108+
}
109+
fmt.Println("+")
110+
111+
// Print header
112+
for i, header := range headers {
113+
fmt.Printf("| %-*s", widths[i], header)
114+
}
115+
fmt.Println("|")
116+
117+
// Print separator
118+
for _, width := range widths {
119+
fmt.Print("|", strings.Repeat("-", width+1))
120+
}
121+
fmt.Println("|")
122+
123+
// Print data rows
124+
for _, holder := range s {
125+
fmt.Printf("| %-*s| %-*s| %-*d| %-*d|\n",
126+
widths[0], holder.StrategyAddress.Hex(),
127+
widths[1], holder.AVSAddress.Hex(),
128+
widths[2], holder.OperatorSetId,
129+
widths[3], holder.SlashableMagnitude)
130+
}
131+
132+
// print dashes
133+
for _, width := range widths {
134+
fmt.Print("+" + strings.Repeat("-", width+1))
135+
}
136+
fmt.Println("+")
137+
}
138+
139+
func (s SlashableMagnitudeHolders) PrintJSON() {
140+
json, err := json.MarshalIndent(s, "", " ")
141+
if err != nil {
142+
fmt.Println("Error marshalling to JSON:", err)
143+
return
144+
}
145+
fmt.Println(string(json))
146+
}

pkg/operator/allocations/update.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func updateAllocations(cCtx *cli.Context, p utils.Prompter) error {
7979
}
8080

8181
// Temp to test modify allocations
82-
avsDirectoryAddress = "0x8BffE5a668DB26bc5Ce8dC9C0096fB634747b62A"
82+
avsDirectoryAddress = "0x2a9854D331B8142d024E4007fB4A34311c5176cE"
8383

8484
elReader, err := elcontracts.NewReaderFromConfig(
8585
elcontracts.Config{
@@ -352,7 +352,11 @@ func getMagnitudes(
352352
reader elChainReader,
353353
) (map[gethcommon.Address]uint64, error) {
354354
strategyTotalMagnitudes := make(map[gethcommon.Address]uint64, len(strategies))
355-
totalMagnitudes, err := reader.GetTotalMagnitudes(&bind.CallOpts{Context: context.Background()}, operatorAddress, strategies)
355+
totalMagnitudes, err := reader.GetTotalMagnitudes(
356+
&bind.CallOpts{Context: context.Background()},
357+
operatorAddress,
358+
strategies,
359+
)
356360
if err != nil {
357361
return nil, err
358362
}

pkg/operator/config/create.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ func promptOperatorInfo(config *types.OperatorConfig, p utils.Prompter) (types.O
159159
config.EthRPCUrl = rpcUrl
160160

161161
// Prompt for allocation delay
162-
allocationDelay, err := p.InputInteger("Enter your allocation delay (in seconds, default is 17.5 days):", "1512000", "",
162+
allocationDelay, err := p.InputInteger(
163+
"Enter your allocation delay (in seconds, default is 17.5 days):",
164+
"1512000",
165+
"",
163166
func(i int64) error {
164167
if i < 0 {
165168
return errors.New("allocation delay should be non-negative")
@@ -172,13 +175,18 @@ func promptOperatorInfo(config *types.OperatorConfig, p utils.Prompter) (types.O
172175
}
173176

174177
// confirm again
175-
confirm, err := p.Confirm("Are you sure you want to set the allocation delay to " + strconv.FormatInt(allocationDelay, 10) + " seconds? This cannot be changed once set.")
178+
confirm, err := p.Confirm(
179+
"Are you sure you want to set the allocation delay to " + strconv.FormatInt(
180+
allocationDelay,
181+
10,
182+
) + " seconds? This cannot be changed once set.",
183+
)
176184
if err != nil {
177185
return types.OperatorConfig{}, err
178186
}
179187

180188
if confirm {
181-
config.AllocationDelay = uint32(allocationDelay)
189+
config.Operator.AllocationDelay = uint32(allocationDelay)
182190
} else {
183191
return types.OperatorConfig{}, errors.New("operator cancelled")
184192
}

pkg/operator/register.go

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func RegisterCmd(p utils.Prompter) *cli.Command {
4545

4646
configurationFilePath := args.Get(0)
4747
operatorCfg, err := common.ValidateAndReturnConfig(configurationFilePath, logger)
48+
logger.Debugf("operatorCfg: %v", operatorCfg)
4849
if err != nil {
4950
return err
5051
}

pkg/types/operator_config.go

-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ type OperatorConfig struct {
2828
EthRPCUrl string `yaml:"eth_rpc_url"`
2929
ChainId big.Int `yaml:"chain_id"`
3030
SignerConfig SignerConfig
31-
AllocationDelay uint32 `yaml:"allocation_delay"`
3231
}
3332

3433
func (o *OperatorConfig) MarshalYAML() (interface{}, error) {
@@ -65,7 +64,6 @@ func (o *OperatorConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
6564
SignerType SignerType `yaml:"signer_type"`
6665
Fireblocks FireblocksConfig `yaml:"fireblocks"`
6766
Web3 Web3SignerConfig `yaml:"web3"`
68-
AllocationDelay uint32 `yaml:"allocation_delay"`
6967
}
7068
if err := unmarshal(&aux); err != nil {
7169
return err
@@ -75,7 +73,6 @@ func (o *OperatorConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
7573
o.ELAVSDirectoryAddress = aux.ELAVSDirectoryAddress
7674
o.ELRewardsCoordinatorAddress = aux.ELRewardsCoordinatorAddress
7775
o.EthRPCUrl = aux.EthRPCUrl
78-
o.AllocationDelay = aux.AllocationDelay
7976

8077
chainId := new(big.Int)
8178
chainId.SetInt64(aux.ChainId)

pkg/utils/utils.go

+10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ func GetAVSDirectoryAddress(chainID *big.Int) (string, error) {
5151
}
5252
}
5353

54+
func GetDelegationManagerAddress(chainID *big.Int) (string, error) {
55+
chainIDInt := chainID.Int64()
56+
chainMetadata, ok := ChainMetadataMap[chainIDInt]
57+
if !ok {
58+
return "", fmt.Errorf("chain ID %d not supported", chainIDInt)
59+
} else {
60+
return chainMetadata.ELDelegationManagerAddress, nil
61+
}
62+
}
63+
5464
func GetRewardCoordinatorAddress(chainID *big.Int) (string, error) {
5565
chainIDInt := chainID.Int64()
5666
chainMetadata, ok := ChainMetadataMap[chainIDInt]

0 commit comments

Comments
 (0)