Skip to content

Commit a839dc5

Browse files
committed
working slashing
1 parent 3c6cac7 commit a839dc5

File tree

5 files changed

+148
-121
lines changed

5 files changed

+148
-121
lines changed

pkg/internal/common/eth.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ func ShortEthAddress(address common.Address) string {
6262
return fmt.Sprintf("%s...%s", address.Hex()[:6], address.Hex()[len(address.Hex())-4:])
6363
}
6464

65-
func FormatNumberWithUnderscores(n uint64) string {
66-
// Convert the number to a string
67-
numStr := strconv.FormatUint(n, 10)
65+
func Uint64ToString(num uint64) string {
66+
return strconv.FormatUint(num, 10)
67+
}
68+
69+
func FormatNumberWithUnderscores(numStr string) string {
6870

6971
// If the number is less than 1000, no formatting is needed
7072
if len(numStr) <= 3 {

pkg/operator/allocations/initializedelay.go

Lines changed: 1 addition & 1 deletion
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("0x1a597729A7dCfeDDD1f6130fBb099892B7623FAd")
54+
config.delegationManagerAddress = gethcommon.HexToAddress("0xFF30144A9A749144e88bEb4FAbF020Cc7F71d2dC")
5555

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

pkg/operator/allocations/show.go

Lines changed: 83 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package allocations
22

33
import (
44
"fmt"
5+
"math/big"
56
"sort"
67

78
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common"
@@ -21,6 +22,11 @@ import (
2122
"github.com/urfave/cli/v2"
2223
)
2324

25+
var (
26+
// PrecisionFactor comes from the allocation manager contract
27+
PrecisionFactor = big.NewInt(1e18)
28+
)
29+
2430
func ShowCmd(p utils.Prompter) *cli.Command {
2531
showCmd := &cli.Command{
2632
Name: "show",
@@ -53,7 +59,7 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
5359
}
5460

5561
// Temp to test modify allocations
56-
config.delegationManagerAddress = gethcommon.HexToAddress("0x1a597729A7dCfeDDD1f6130fBb099892B7623FAd")
62+
config.delegationManagerAddress = gethcommon.HexToAddress("0xFF30144A9A749144e88bEb4FAbF020Cc7F71d2dC")
5763

5864
elReader, err := elcontracts.NewReaderFromConfig(
5965
elcontracts.Config{
@@ -76,7 +82,25 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
7682
if err != nil {
7783
return eigenSdkUtils.WrapError("failed to get allocatable magnitude", err)
7884
}
79-
logger.Debugf("Allocatable magnitude for strategy %v: %s", strategyAddress, common.FormatNumberWithUnderscores(allocatableMagnitude))
85+
logger.Debugf(
86+
"Allocatable magnitude for strategy %v: %s",
87+
strategyAddress,
88+
common.FormatNumberWithUnderscores(common.Uint64ToString(allocatableMagnitude)),
89+
)
90+
}
91+
92+
// for each strategy address, get the total magnitude
93+
totalMagnitudeMap := make(map[string]uint64)
94+
totalMagnitudes, err := elReader.GetTotalMagnitudes(
95+
&bind.CallOpts{Context: ctx},
96+
config.operatorAddress,
97+
config.strategyAddresses,
98+
)
99+
if err != nil {
100+
return eigenSdkUtils.WrapError("failed to get allocatable magnitude", err)
101+
}
102+
for i, strategyAddress := range config.strategyAddresses {
103+
totalMagnitudeMap[strategyAddress.String()] = totalMagnitudes[i]
80104
}
81105

82106
opSets, slashableMagnitudes, err := elReader.GetCurrentSlashableMagnitudes(
@@ -89,7 +113,6 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
89113
}
90114

91115
// Get Pending allocations
92-
//pendingAllocationsDetails := make(AllocationDetailsHolder, 0)
93116
pendingAllocationMap := make(map[string]AllocDetails)
94117
for _, strategyAddress := range config.strategyAddresses {
95118
pendingAllocations, timestamps, err := elReader.GetPendingAllocations(
@@ -107,21 +130,13 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
107130
if pendingAllocation == 0 && timestamp == 0 {
108131
continue
109132
}
110-
//pendingAllocationsDetails = append(pendingAllocationsDetails, AllocationDetails{
111-
// StrategyAddress: strategyAddress,
112-
// AVSAddress: opSet.Avs,
113-
// OperatorSetId: opSet.OperatorSetId,
114-
// Allocation: pendingAllocation,
115-
// Timestamp: timestamp,
116-
//})
117133
pendingAllocationMap[getUniqueKey(strategyAddress, opSet)] = AllocDetails{
118134
Magnitude: pendingAllocation,
119135
Timestamp: timestamp,
120136
}
121137
}
122138
}
123139

124-
//pendingDeallocationsDetails := make(AllocationDetailsHolder, 0)
125140
pendingdeAllocationMap := make(map[string]AllocDetails)
126141
for _, strategyAddress := range config.strategyAddresses {
127142
pendingDeallocations, err := elReader.GetPendingDeallocations(
@@ -138,20 +153,23 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
138153
if pendingAllocation.MagnitudeDiff == 0 && pendingAllocation.CompletableTimestamp == 0 {
139154
continue
140155
}
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-
//})
148156
pendingdeAllocationMap[getUniqueKey(strategyAddress, opSet)] = AllocDetails{
149157
Magnitude: pendingAllocation.MagnitudeDiff,
150158
Timestamp: pendingAllocation.CompletableTimestamp,
151159
}
152160
}
153161
}
154162

163+
// Get Operator Shares
164+
operatorScaledSharesMap := make(map[string]*big.Int)
165+
for _, strategyAddress := range config.strategyAddresses {
166+
shares, err := elReader.GetOperatorScaledShares(&bind.CallOpts{}, config.operatorAddress, strategyAddress)
167+
if err != nil {
168+
return err
169+
}
170+
operatorScaledSharesMap[strategyAddress.String()] = shares
171+
}
172+
155173
slashableMagnitudeHolders := make(SlashableMagnitudeHolders, 0)
156174
for i, strategyAddress := range config.strategyAddresses {
157175
slashableMagnitude := slashableMagnitudes[i]
@@ -171,36 +189,54 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
171189
newAllocation = currSlashableMag
172190
currSlashableMag = currSlashableMag + newAllocationDiff
173191
}
192+
193+
operatorScaledShares := operatorScaledSharesMap[strategyAddress.String()]
194+
195+
currSlashableMagBigInt := big.NewInt(1)
196+
currSlashableMagBigInt = currSlashableMagBigInt.SetUint64(currSlashableMag)
197+
198+
scaledOpShares := big.NewInt(1)
199+
scaledOpShares = scaledOpShares.Set(operatorScaledShares)
200+
scaledOpShares = scaledOpShares.Div(scaledOpShares, PrecisionFactor)
201+
shares := scaledOpShares.Mul(scaledOpShares, currSlashableMagBigInt)
202+
203+
newShares := getSharesFromMagnitude(operatorScaledShares, newAllocation)
204+
205+
percentageShares := big.NewInt(1)
206+
percentageShares = percentageShares.Mul(scaledOpShares, big.NewInt(100))
207+
percentageSharesFloat := new(
208+
big.Float,
209+
).Quo(new(big.Float).SetInt(percentageShares), new(big.Float).SetInt(operatorScaledShares))
174210
slashableMagnitudeHolders = append(slashableMagnitudeHolders, SlashableMagnitudesHolder{
175211
StrategyAddress: strategyAddress,
176212
AVSAddress: opSet.Avs,
177213
OperatorSetId: opSet.OperatorSetId,
178214
SlashableMagnitude: currSlashableMag,
179215
NewMagnitude: newAllocation,
180216
NewMagnitudeTimestamp: newTimestamp,
217+
Shares: shares,
218+
SharesPercentage: percentageSharesFloat.String(),
219+
NewAllocationShares: newShares,
181220
})
182221
}
183222
}
184223

224+
// Get Operator Shares
225+
operatorSharesMap := make(map[string]*big.Int)
226+
for _, strategyAddress := range config.strategyAddresses {
227+
shares, err := elReader.GetOperatorShares(&bind.CallOpts{}, config.operatorAddress, strategyAddress)
228+
if err != nil {
229+
return err
230+
}
231+
operatorSharesMap[strategyAddress.String()] = shares
232+
}
233+
234+
for key, val := range operatorSharesMap {
235+
fmt.Printf("Strategy Address: %s, Shares %s\n", key, val.String())
236+
}
237+
185238
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()
202-
203-
fmt.Println("------------------Current Slashable Magnitudes---------------------")
239+
fmt.Printf("------------------ Allocation State for %s ---------------------\n", config.operatorAddress.String())
204240
if config.outputType == string(common.OutputType_Json) {
205241
slashableMagnitudeHolders.PrintJSON()
206242
} else {
@@ -210,6 +246,17 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
210246
return nil
211247
}
212248

249+
func getSharesFromMagnitude(totalScaledShare *big.Int, magnitude uint64) *big.Int {
250+
slashableMagBigInt := big.NewInt(1)
251+
slashableMagBigInt = slashableMagBigInt.SetUint64(magnitude)
252+
253+
scaledOpShares := big.NewInt(1)
254+
scaledOpShares = scaledOpShares.Set(totalScaledShare)
255+
scaledOpShares = scaledOpShares.Div(scaledOpShares, PrecisionFactor)
256+
shares := scaledOpShares.Mul(scaledOpShares, slashableMagBigInt)
257+
return shares
258+
}
259+
213260
func getUniqueKey(strategyAddress gethcommon.Address, opSet contractIAllocationManager.OperatorSet) string {
214261
return fmt.Sprintf("%s-%s-%d", strategyAddress.String(), opSet.Avs.String(), opSet.OperatorSetId)
215262
}

0 commit comments

Comments
 (0)