Skip to content

Commit c9de4de

Browse files
committed
add more code
1 parent 9f3068a commit c9de4de

File tree

6 files changed

+172
-15
lines changed

6 files changed

+172
-15
lines changed

pkg/internal/common/eth.go

+4
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ func ConvertStringSliceToGethAddressSlice(addresses []string) []common.Address {
5656
}
5757
return gethAddresses
5858
}
59+
60+
func ShortEthAddress(address common.Address) string {
61+
return fmt.Sprintf("%s...%s", address.Hex()[:6], address.Hex()[len(address.Hex())-4:])
62+
}

pkg/internal/common/helper.go

+10
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,16 @@ func GetAVSDirectoryAddress(chainID *big.Int) (string, error) {
317317
}
318318
}
319319

320+
func GetDelegationManagerAddress(chainID *big.Int) (string, error) {
321+
chainIDInt := chainID.Int64()
322+
chainMetadata, ok := ChainMetadataMap[chainIDInt]
323+
if !ok {
324+
return "", fmt.Errorf("chain ID %d not supported", chainIDInt)
325+
} else {
326+
return chainMetadata.ELDelegationManagerAddress, nil
327+
}
328+
}
329+
320330
func GetTransactionLink(txHash string, chainId *big.Int) string {
321331
chainIDInt := chainId.Int64()
322332
chainMetadata, ok := ChainMetadataMap[chainIDInt]

pkg/operator/allocations/initializedelay.go

+4-4
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.delegationManagerAddress = gethcommon.HexToAddress("0xD9DFF502e91aE5887399C8ca11a0708dc1ee1cbf")
54+
config.delegationManagerAddress = gethcommon.HexToAddress("0xec91e43612896E7D45736cE751bea6dbf1BBEdB5")
5555

5656
if config.broadcast {
5757
confirm, err := p.Confirm(
@@ -80,7 +80,7 @@ func initializeDelayAction(cCtx *cli.Context, p utils.Prompter) error {
8080
return eigenSdkUtils.WrapError("failed to get EL writer", err)
8181
}
8282

83-
receipt, err := eLWriter.InitializeAllocationDelay(ctx, config.allocationDelay, true)
83+
receipt, err := eLWriter.InitializeAllocationDelay(ctx, config.operatorAddress, config.allocationDelay, true)
8484
if err != nil {
8585
return err
8686
}
@@ -102,7 +102,7 @@ func initializeDelayAction(cCtx *cli.Context, p utils.Prompter) error {
102102
noSendTxOpts.GasLimit = 150_000
103103
}
104104

105-
unsignedTx, err := contractBindings.DelegationManager.InitializeAllocationDelay(noSendTxOpts, config.allocationDelay)
105+
unsignedTx, err := contractBindings.AllocationManager.SetAllocationDelay(noSendTxOpts, config.operatorAddress, config.allocationDelay)
106106
if err != nil {
107107
return eigenSdkUtils.WrapError("failed to create unsigned tx", err)
108108
}
@@ -186,7 +186,7 @@ func readAndValidateAllocationDelayConfig(c *cli.Context, logger logging.Logger)
186186
logger.Debugf("Failed to get signer config: %s", err)
187187
}
188188

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

pkg/operator/allocations/show.go

+78-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package allocations
22

33
import (
4+
"fmt"
45
"sort"
56

67
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common"
@@ -51,7 +52,7 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
5152
}
5253

5354
// Temp to test modify allocations
54-
config.delegationManagerAddress = gethcommon.HexToAddress("0xD9DFF502e91aE5887399C8ca11a0708dc1ee1cbf")
55+
config.delegationManagerAddress = gethcommon.HexToAddress("0xec91e43612896E7D45736cE751bea6dbf1BBEdB5")
5556

5657
elReader, err := elcontracts.NewReaderFromConfig(
5758
elcontracts.Config{
@@ -77,7 +78,7 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
7778
logger.Debugf("Allocatable magnitude for strategy %v: %d", strategyAddress, allocatableMagnitude)
7879
}
7980

80-
opSet, slashableMagnitudes, err := elReader.GetCurrentSlashableMagnitudes(
81+
opSets, slashableMagnitudes, err := elReader.GetCurrentSlashableMagnitudes(
8182
&bind.CallOpts{Context: ctx},
8283
config.operatorAddress,
8384
config.strategyAddresses,
@@ -89,7 +90,7 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
8990
slashableMagnitudeHolders := make(SlashableMagnitudeHolders, 0)
9091
for i, strategyAddress := range config.strategyAddresses {
9192
slashableMagnitude := slashableMagnitudes[i]
92-
for j, opSet := range opSet {
93+
for j, opSet := range opSets {
9394
slashableMagnitudeHolders = append(slashableMagnitudeHolders, SlashableMagnitudesHolder{
9495
StrategyAddress: strategyAddress,
9596
AVSAddress: opSet.Avs,
@@ -99,6 +100,79 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
99100
}
100101
}
101102

103+
// Get Pending allocations
104+
pendingAllocationsDetails := make(AllocationDetailsHolder, 0)
105+
for _, strategyAddress := range config.strategyAddresses {
106+
pendingAllocations, timestamps, err := elReader.GetPendingAllocations(
107+
&bind.CallOpts{Context: ctx},
108+
config.operatorAddress,
109+
strategyAddress,
110+
opSets,
111+
)
112+
if err != nil {
113+
return eigenSdkUtils.WrapError("failed to get pending allocations", err)
114+
}
115+
for i, opSet := range opSets {
116+
pendingAllocation := pendingAllocations[i]
117+
timestamp := timestamps[i]
118+
if pendingAllocation == 0 && timestamp == 0 {
119+
continue
120+
}
121+
pendingAllocationsDetails = append(pendingAllocationsDetails, AllocationDetails{
122+
StrategyAddress: strategyAddress,
123+
AVSAddress: opSet.Avs,
124+
OperatorSetId: opSet.OperatorSetId,
125+
Allocation: pendingAllocation,
126+
Timestamp: timestamp,
127+
})
128+
}
129+
}
130+
131+
pendingDeallocationsDetails := make(AllocationDetailsHolder, 0)
132+
for _, strategyAddress := range config.strategyAddresses {
133+
pendingDeallocations, err := elReader.GetPendingDeallocations(
134+
&bind.CallOpts{Context: ctx},
135+
config.operatorAddress,
136+
strategyAddress,
137+
opSets,
138+
)
139+
if err != nil {
140+
return eigenSdkUtils.WrapError("failed to get pending deallocations", err)
141+
}
142+
for i, opSet := range opSets {
143+
pendingAllocation := pendingDeallocations[i]
144+
if pendingAllocation.MagnitudeDiff == 0 && pendingAllocation.CompletableTimestamp == 0 {
145+
continue
146+
}
147+
pendingDeallocationsDetails = append(pendingDeallocationsDetails, AllocationDetails{
148+
StrategyAddress: strategyAddress,
149+
AVSAddress: opSet.Avs,
150+
OperatorSetId: opSet.OperatorSetId,
151+
Allocation: pendingAllocation.MagnitudeDiff,
152+
Timestamp: pendingAllocation.CompletableTimestamp,
153+
})
154+
}
155+
}
156+
157+
fmt.Println()
158+
fmt.Println("------------------Pending Allocations---------------------")
159+
if config.outputType == string(common.OutputType_Json) {
160+
pendingAllocationsDetails.PrintJSON()
161+
} else {
162+
pendingAllocationsDetails.PrintPretty()
163+
}
164+
fmt.Println()
165+
166+
fmt.Println()
167+
fmt.Println("------------------Pending Deallocations---------------------")
168+
if config.outputType == string(common.OutputType_Json) {
169+
pendingDeallocationsDetails.PrintJSON()
170+
} else {
171+
pendingDeallocationsDetails.PrintPretty()
172+
}
173+
fmt.Println()
174+
175+
fmt.Println("------------------Current Slashable Magnitudes---------------------")
102176
if config.outputType == string(common.OutputType_Json) {
103177
slashableMagnitudeHolders.PrintJSON()
104178
} else {
@@ -119,7 +193,7 @@ func readAndValidateShowConfig(cCtx *cli.Context, logger *logging.Logger) (*show
119193
outputType := cCtx.String(flags.OutputTypeFlag.Name)
120194

121195
chainId := utils.NetworkNameToChainId(network)
122-
delegationManagerAddress, err := utils.GetDelegationManagerAddress(chainId)
196+
delegationManagerAddress, err := common.GetDelegationManagerAddress(chainId)
123197
if err != nil {
124198
return nil, err
125199
}

pkg/operator/allocations/types.go

+74-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package allocations
33
import (
44
"encoding/json"
55
"fmt"
6+
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common"
67
"math/big"
78
"strings"
9+
"time"
810

911
"github.com/Layr-Labs/eigenlayer-cli/pkg/types"
1012

@@ -102,7 +104,7 @@ type SlashableMagnitudesHolder struct {
102104
func (s SlashableMagnitudeHolders) PrintPretty() {
103105
// Define column headers and widths
104106
headers := []string{"Strategy Address", "AVS Address", "Operator Set ID", "Slashable Magnitude"}
105-
widths := []int{43, 43, 16, 20}
107+
widths := []int{20, 20, 16, 20}
106108

107109
// print dashes
108110
for _, width := range widths {
@@ -125,8 +127,8 @@ func (s SlashableMagnitudeHolders) PrintPretty() {
125127
// Print data rows
126128
for _, holder := range s {
127129
fmt.Printf("| %-*s| %-*s| %-*d| %-*d|\n",
128-
widths[0], holder.StrategyAddress.Hex(),
129-
widths[1], holder.AVSAddress.Hex(),
130+
widths[0], common.ShortEthAddress(holder.StrategyAddress),
131+
widths[1], common.ShortEthAddress(holder.AVSAddress),
130132
widths[2], holder.OperatorSetId,
131133
widths[3], holder.SlashableMagnitude)
132134
}
@@ -139,10 +141,77 @@ func (s SlashableMagnitudeHolders) PrintPretty() {
139141
}
140142

141143
func (s SlashableMagnitudeHolders) PrintJSON() {
142-
json, err := json.MarshalIndent(s, "", " ")
144+
obj, err := json.MarshalIndent(s, "", " ")
143145
if err != nil {
144146
fmt.Println("Error marshalling to JSON:", err)
145147
return
146148
}
147-
fmt.Println(string(json))
149+
fmt.Println(string(obj))
150+
}
151+
152+
type AllocationDetailsHolder []AllocationDetails
153+
154+
type AllocationDetails struct {
155+
StrategyAddress gethcommon.Address
156+
AVSAddress gethcommon.Address
157+
OperatorSetId uint32
158+
Allocation uint64
159+
Timestamp uint32
160+
}
161+
162+
func (a AllocationDetailsHolder) PrintPretty() {
163+
// Define column headers and widths
164+
headers := []string{"Strategy Address", "AVS Address", "Operator Set ID", "Allocation", "Application Timestamp"}
165+
widths := []int{20, 20, 16, 20, 25}
166+
167+
// print dashes
168+
for _, width := range widths {
169+
fmt.Print("+" + strings.Repeat("-", width+1))
170+
}
171+
fmt.Println("+")
172+
173+
// Print header
174+
for i, header := range headers {
175+
fmt.Printf("| %-*s", widths[i], header)
176+
}
177+
fmt.Println("|")
178+
179+
// Print separator
180+
for _, width := range widths {
181+
fmt.Print("|", strings.Repeat("-", width+1))
182+
}
183+
fmt.Println("|")
184+
185+
// Print data rows
186+
for _, holder := range a {
187+
// Example timestamp (Unix timestamp in seconds)
188+
timestamp := int64(holder.Timestamp)
189+
190+
// Convert timestamp to time.Time
191+
t := time.Unix(timestamp, 0)
192+
193+
// Format the time as a string
194+
formattedTime := t.Format("2006-01-02 15:04:05")
195+
fmt.Printf("| %-*s| %-*s| %-*d| %-*d| %-*s|\n",
196+
widths[0], common.ShortEthAddress(holder.StrategyAddress),
197+
widths[1], common.ShortEthAddress(holder.AVSAddress),
198+
widths[2], holder.OperatorSetId,
199+
widths[3], holder.Allocation,
200+
widths[4], formattedTime)
201+
}
202+
203+
// print dashes
204+
for _, width := range widths {
205+
fmt.Print("+" + strings.Repeat("-", width+1))
206+
}
207+
fmt.Println("+")
208+
}
209+
210+
func (a AllocationDetailsHolder) PrintJSON() {
211+
obj, err := json.MarshalIndent(a, "", " ")
212+
if err != nil {
213+
fmt.Println("Error marshalling to JSON:", err)
214+
return
215+
}
216+
fmt.Println(string(obj))
148217
}

pkg/operator/allocations/update.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func updateAllocations(cCtx *cli.Context, p utils.Prompter) error {
7474
}
7575

7676
// Temp to test modify Allocations
77-
config.delegationManagerAddress = gethcommon.HexToAddress("0xD9DFF502e91aE5887399C8ca11a0708dc1ee1cbf")
77+
config.delegationManagerAddress = gethcommon.HexToAddress("0xec91e43612896E7D45736cE751bea6dbf1BBEdB5")
7878

7979
elReader, err := elcontracts.NewReaderFromConfig(
8080
elcontracts.Config{
@@ -469,7 +469,7 @@ func readAndValidateUpdateFlags(cCtx *cli.Context, logger logging.Logger) (*upda
469469
csvFilePath := cCtx.String(flags.CSVFileFlag.Name)
470470
chainId := utils.NetworkNameToChainId(network)
471471

472-
delegationManagerAddress, err := utils.GetDelegationManagerAddress(chainId)
472+
delegationManagerAddress, err := common.GetDelegationManagerAddress(chainId)
473473
if err != nil {
474474
return nil, err
475475
}

0 commit comments

Comments
 (0)