Skip to content

Commit dd1bfee

Browse files
committed
add more code
1 parent 700d876 commit dd1bfee

File tree

5 files changed

+184
-74
lines changed

5 files changed

+184
-74
lines changed

Diff for: pkg/internal/common/eth.go

+30
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package common
33
import (
44
"fmt"
55
"math/big"
6+
"strconv"
67
"strings"
78

89
"github.com/ethereum/go-ethereum/common"
@@ -60,3 +61,32 @@ func ConvertStringSliceToGethAddressSlice(addresses []string) []common.Address {
6061
func ShortEthAddress(address common.Address) string {
6162
return fmt.Sprintf("%s...%s", address.Hex()[:6], address.Hex()[len(address.Hex())-4:])
6263
}
64+
65+
func FormatNumberWithUnderscores(n uint64) string {
66+
// Convert the number to a string
67+
numStr := strconv.FormatUint(n, 10)
68+
69+
// If the number is less than 1000, no formatting is needed
70+
if len(numStr) <= 3 {
71+
return numStr
72+
}
73+
74+
// Calculate the number of groups of 3 digits
75+
groups := (len(numStr) - 1) / 3
76+
77+
// Create a slice to hold the result
78+
result := make([]byte, len(numStr)+groups)
79+
80+
// Fill the result slice from right to left
81+
resultIndex := len(result) - 1
82+
for i := len(numStr) - 1; i >= 0; i-- {
83+
if (len(numStr)-i-1)%3 == 0 && i != len(numStr)-1 {
84+
result[resultIndex] = '_'
85+
resultIndex--
86+
}
87+
result[resultIndex] = numStr[i]
88+
resultIndex--
89+
}
90+
91+
return string(result)
92+
}

Diff for: pkg/operator/allocations/initializedelay.go

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

5656
if config.broadcast {
5757
confirm, err := p.Confirm(

Diff for: pkg/operator/allocations/show.go

+77-45
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"
1111

1212
"github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
13+
contractIAllocationManager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IAllocationManager"
1314
"github.com/Layr-Labs/eigensdk-go/logging"
1415
eigenSdkUtils "github.com/Layr-Labs/eigensdk-go/utils"
1516

@@ -52,7 +53,7 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
5253
}
5354

5455
// Temp to test modify allocations
55-
config.delegationManagerAddress = gethcommon.HexToAddress("0xec91e43612896E7D45736cE751bea6dbf1BBEdB5")
56+
config.delegationManagerAddress = gethcommon.HexToAddress("0x1a597729A7dCfeDDD1f6130fBb099892B7623FAd")
5657

5758
elReader, err := elcontracts.NewReaderFromConfig(
5859
elcontracts.Config{
@@ -75,7 +76,7 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
7576
if err != nil {
7677
return eigenSdkUtils.WrapError("failed to get allocatable magnitude", err)
7778
}
78-
logger.Debugf("Allocatable magnitude for strategy %v: %d", strategyAddress, allocatableMagnitude)
79+
logger.Debugf("Allocatable magnitude for strategy %v: %s", strategyAddress, common.FormatNumberWithUnderscores(allocatableMagnitude))
7980
}
8081

8182
opSets, slashableMagnitudes, err := elReader.GetCurrentSlashableMagnitudes(
@@ -87,21 +88,9 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
8788
return eigenSdkUtils.WrapError("failed to get slashable magnitude", err)
8889
}
8990

90-
slashableMagnitudeHolders := make(SlashableMagnitudeHolders, 0)
91-
for i, strategyAddress := range config.strategyAddresses {
92-
slashableMagnitude := slashableMagnitudes[i]
93-
for j, opSet := range opSets {
94-
slashableMagnitudeHolders = append(slashableMagnitudeHolders, SlashableMagnitudesHolder{
95-
StrategyAddress: strategyAddress,
96-
AVSAddress: opSet.Avs,
97-
OperatorSetId: opSet.OperatorSetId,
98-
SlashableMagnitude: slashableMagnitude[j],
99-
})
100-
}
101-
}
102-
10391
// Get Pending allocations
104-
pendingAllocationsDetails := make(AllocationDetailsHolder, 0)
92+
//pendingAllocationsDetails := make(AllocationDetailsHolder, 0)
93+
pendingAllocationMap := make(map[string]AllocDetails)
10594
for _, strategyAddress := range config.strategyAddresses {
10695
pendingAllocations, timestamps, err := elReader.GetPendingAllocations(
10796
&bind.CallOpts{Context: ctx},
@@ -118,17 +107,22 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
118107
if pendingAllocation == 0 && timestamp == 0 {
119108
continue
120109
}
121-
pendingAllocationsDetails = append(pendingAllocationsDetails, AllocationDetails{
122-
StrategyAddress: strategyAddress,
123-
AVSAddress: opSet.Avs,
124-
OperatorSetId: opSet.OperatorSetId,
125-
Allocation: pendingAllocation,
126-
Timestamp: timestamp,
127-
})
110+
//pendingAllocationsDetails = append(pendingAllocationsDetails, AllocationDetails{
111+
// StrategyAddress: strategyAddress,
112+
// AVSAddress: opSet.Avs,
113+
// OperatorSetId: opSet.OperatorSetId,
114+
// Allocation: pendingAllocation,
115+
// Timestamp: timestamp,
116+
//})
117+
pendingAllocationMap[getUniqueKey(strategyAddress, opSet)] = AllocDetails{
118+
Magnitude: pendingAllocation,
119+
Timestamp: timestamp,
120+
}
128121
}
129122
}
130123

131-
pendingDeallocationsDetails := make(AllocationDetailsHolder, 0)
124+
//pendingDeallocationsDetails := make(AllocationDetailsHolder, 0)
125+
pendingdeAllocationMap := make(map[string]AllocDetails)
132126
for _, strategyAddress := range config.strategyAddresses {
133127
pendingDeallocations, err := elReader.GetPendingDeallocations(
134128
&bind.CallOpts{Context: ctx},
@@ -144,33 +138,67 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
144138
if pendingAllocation.MagnitudeDiff == 0 && pendingAllocation.CompletableTimestamp == 0 {
145139
continue
146140
}
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-
})
141+
//pendingDeallocationsDetails = append(pendingDeallocationsDetails, AllocationDetails{
142+
// StrategyAddress: strategyAddress,
143+
// AVSAddress: opSet.Avs,
144+
// OperatorSetId: opSet.OperatorSetId,
145+
// Allocation: pendingAllocation.MagnitudeDiff,
146+
// Timestamp: pendingAllocation.CompletableTimestamp,
147+
//})
148+
pendingdeAllocationMap[getUniqueKey(strategyAddress, opSet)] = AllocDetails{
149+
Magnitude: pendingAllocation.MagnitudeDiff,
150+
Timestamp: pendingAllocation.CompletableTimestamp,
151+
}
154152
}
155153
}
156154

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()
155+
slashableMagnitudeHolders := make(SlashableMagnitudeHolders, 0)
156+
for i, strategyAddress := range config.strategyAddresses {
157+
slashableMagnitude := slashableMagnitudes[i]
158+
for j, opSet := range opSets {
159+
newAllocation := uint64(0)
160+
newTimestamp := uint32(0)
161+
currSlashableMag := slashableMagnitude[j]
162+
someKey := getUniqueKey(strategyAddress, opSet)
163+
if _, ok := pendingAllocationMap[someKey]; ok {
164+
newAllocation = pendingAllocationMap[someKey].Magnitude
165+
newTimestamp = pendingAllocationMap[someKey].Timestamp
166+
}
165167

166-
fmt.Println()
167-
fmt.Println("------------------Pending Deallocations---------------------")
168-
if config.outputType == string(common.OutputType_Json) {
169-
pendingDeallocationsDetails.PrintJSON()
170-
} else {
171-
pendingDeallocationsDetails.PrintPretty()
168+
if _, ok := pendingdeAllocationMap[someKey]; ok {
169+
newAllocationDiff := pendingdeAllocationMap[someKey].Magnitude
170+
newTimestamp = pendingdeAllocationMap[someKey].Timestamp
171+
newAllocation = currSlashableMag
172+
currSlashableMag = currSlashableMag + newAllocationDiff
173+
}
174+
slashableMagnitudeHolders = append(slashableMagnitudeHolders, SlashableMagnitudesHolder{
175+
StrategyAddress: strategyAddress,
176+
AVSAddress: opSet.Avs,
177+
OperatorSetId: opSet.OperatorSetId,
178+
SlashableMagnitude: currSlashableMag,
179+
NewMagnitude: newAllocation,
180+
NewMagnitudeTimestamp: newTimestamp,
181+
})
182+
}
172183
}
184+
173185
fmt.Println()
186+
//fmt.Println("------------------Pending Allocations---------------------")
187+
//if config.outputType == string(common.OutputType_Json) {
188+
// pendingAllocationsDetails.PrintJSON()
189+
//} else {
190+
// pendingAllocationsDetails.PrintPretty()
191+
//}
192+
//fmt.Println()
193+
//
194+
//fmt.Println()
195+
//fmt.Println("------------------Pending Deallocations---------------------")
196+
//if config.outputType == string(common.OutputType_Json) {
197+
// pendingDeallocationsDetails.PrintJSON()
198+
//} else {
199+
// pendingDeallocationsDetails.PrintPretty()
200+
//}
201+
//fmt.Println()
174202

175203
fmt.Println("------------------Current Slashable Magnitudes---------------------")
176204
if config.outputType == string(common.OutputType_Json) {
@@ -182,6 +210,10 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
182210
return nil
183211
}
184212

213+
func getUniqueKey(strategyAddress gethcommon.Address, opSet contractIAllocationManager.OperatorSet) string {
214+
return fmt.Sprintf("%s-%s-%d", strategyAddress.String(), opSet.Avs.String(), opSet.OperatorSetId)
215+
}
216+
185217
func readAndValidateShowConfig(cCtx *cli.Context, logger *logging.Logger) (*showConfig, error) {
186218
network := cCtx.String(flags.NetworkFlag.Name)
187219
rpcUrl := cCtx.String(flags.ETHRpcUrlFlag.Name)

Diff for: pkg/operator/allocations/types.go

+74-26
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,54 @@ type BulkModifyAllocations struct {
2020
AllocatableMagnitudes map[gethcommon.Address]uint64
2121
}
2222

23-
func (b *BulkModifyAllocations) Print() {
24-
for _, a := range b.Allocations {
25-
fmt.Printf(
26-
"Strategy: %s, Expected Total Magnitude: %d, Allocatable Magnitude %d\n",
27-
a.Strategy.Hex(),
28-
a.ExpectedTotalMagnitude,
29-
b.AllocatableMagnitudes[a.Strategy],
30-
)
23+
func (b *BulkModifyAllocations) PrintPretty() {
24+
25+
fmt.Println()
26+
fmt.Println("Allocations to be Updated")
27+
allocations := b.Allocations
28+
headers := []string{"Strategy", "Expected Total Magnitude", "Allocatable Magnitude", "Operator Set ID", "AVS", "Magnitude"}
29+
widths := []int{20, 25, 25, 20, 20, 25}
30+
31+
// print dashes
32+
for _, width := range widths {
33+
fmt.Print("+" + strings.Repeat("-", width+1))
34+
}
35+
36+
fmt.Println("+")
37+
38+
// Print header
39+
for i, header := range headers {
40+
fmt.Printf("| %-*s", widths[i], header)
41+
}
42+
43+
fmt.Println("|")
44+
45+
// Print separator
46+
for _, width := range widths {
47+
fmt.Print("|", strings.Repeat("-", width+1))
48+
}
49+
50+
fmt.Println("|")
51+
52+
// Print data rows
53+
for _, a := range allocations {
3154
for i, opSet := range a.OperatorSets {
32-
fmt.Printf(
33-
"Operator Set: %d, AVS: %s, Magnitude: %d\n",
34-
opSet.OperatorSetId,
35-
opSet.Avs.Hex(),
36-
a.Magnitudes[i],
37-
)
55+
fmt.Printf("| %-*s| %-*s| %-*s| %-*d| %-*s| %-*s|\n",
56+
widths[0], common.ShortEthAddress(a.Strategy),
57+
widths[1], common.FormatNumberWithUnderscores(a.ExpectedTotalMagnitude),
58+
widths[2], common.FormatNumberWithUnderscores(b.AllocatableMagnitudes[a.Strategy]),
59+
widths[3], opSet.OperatorSetId,
60+
widths[4], common.ShortEthAddress(opSet.Avs),
61+
widths[5], common.FormatNumberWithUnderscores(a.Magnitudes[i]))
3862
}
39-
fmt.Println()
4063
}
64+
65+
// print dashes
66+
for _, width := range widths {
67+
fmt.Print("+" + strings.Repeat("-", width+1))
68+
}
69+
70+
fmt.Println("+")
4171
}
4272

4373
type updateConfig struct {
@@ -95,16 +125,18 @@ type showConfig struct {
95125
type SlashableMagnitudeHolders []SlashableMagnitudesHolder
96126

97127
type SlashableMagnitudesHolder struct {
98-
StrategyAddress gethcommon.Address
99-
AVSAddress gethcommon.Address
100-
OperatorSetId uint32
101-
SlashableMagnitude uint64
128+
StrategyAddress gethcommon.Address
129+
AVSAddress gethcommon.Address
130+
OperatorSetId uint32
131+
SlashableMagnitude uint64
132+
NewMagnitude uint64
133+
NewMagnitudeTimestamp uint32
102134
}
103135

104136
func (s SlashableMagnitudeHolders) PrintPretty() {
105137
// Define column headers and widths
106-
headers := []string{"Strategy Address", "AVS Address", "Operator Set ID", "Slashable Magnitude"}
107-
widths := []int{20, 20, 16, 20}
138+
headers := []string{"Strategy Address", "AVS Address", "Operator Set ID", "Slashable Magnitude", "New Magnitude", "New Magnitude Timestamp"}
139+
widths := []int{20, 20, 16, 25, 25, 25}
108140

109141
// print dashes
110142
for _, width := range widths {
@@ -126,11 +158,22 @@ func (s SlashableMagnitudeHolders) PrintPretty() {
126158

127159
// Print data rows
128160
for _, holder := range s {
129-
fmt.Printf("| %-*s| %-*s| %-*d| %-*d|\n",
161+
// Example timestamp (Unix timestamp in seconds)
162+
timestamp := int64(holder.NewMagnitudeTimestamp)
163+
164+
// Convert timestamp to time.Time
165+
t := time.Unix(timestamp, 0)
166+
167+
// Format the time as a string
168+
formattedTime := t.Format("2006-01-02 15:04:05")
169+
fmt.Printf("| %-*s| %-*s| %-*d| %-*s| %-*s| %-*s|\n",
130170
widths[0], common.ShortEthAddress(holder.StrategyAddress),
131171
widths[1], common.ShortEthAddress(holder.AVSAddress),
132172
widths[2], holder.OperatorSetId,
133-
widths[3], holder.SlashableMagnitude)
173+
widths[3], common.FormatNumberWithUnderscores(holder.SlashableMagnitude),
174+
widths[4], common.FormatNumberWithUnderscores(holder.NewMagnitude),
175+
widths[5], formattedTime,
176+
)
134177
}
135178

136179
// print dashes
@@ -162,7 +205,7 @@ type AllocationDetails struct {
162205
func (a AllocationDetailsHolder) PrintPretty() {
163206
// Define column headers and widths
164207
headers := []string{"Strategy Address", "AVS Address", "Operator Set ID", "Allocation", "Application Timestamp"}
165-
widths := []int{20, 20, 16, 20, 25}
208+
widths := []int{20, 20, 16, 25, 25}
166209

167210
// print dashes
168211
for _, width := range widths {
@@ -192,11 +235,11 @@ func (a AllocationDetailsHolder) PrintPretty() {
192235

193236
// Format the time as a string
194237
formattedTime := t.Format("2006-01-02 15:04:05")
195-
fmt.Printf("| %-*s| %-*s| %-*d| %-*d| %-*s|\n",
238+
fmt.Printf("| %-*s| %-*s| %-*d| %-*s| %-*s|\n",
196239
widths[0], common.ShortEthAddress(holder.StrategyAddress),
197240
widths[1], common.ShortEthAddress(holder.AVSAddress),
198241
widths[2], holder.OperatorSetId,
199-
widths[3], holder.Allocation,
242+
widths[3], common.FormatNumberWithUnderscores(holder.Allocation),
200243
widths[4], formattedTime)
201244
}
202245

@@ -215,3 +258,8 @@ func (a AllocationDetailsHolder) PrintJSON() {
215258
}
216259
fmt.Println(string(obj))
217260
}
261+
262+
type AllocDetails struct {
263+
Magnitude uint64
264+
Timestamp uint32
265+
}

0 commit comments

Comments
 (0)