1
1
package allocations
2
2
3
3
import (
4
+ "context"
4
5
"fmt"
5
6
"math/big"
6
7
"sort"
@@ -132,7 +133,7 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
132
133
}
133
134
134
135
/*
135
- 5. Get the operator scaled shares for all strategies
136
+ 5. Get the operator shares for all strategies
136
137
*/
137
138
operatorDelegatedSharesMap := make (map [string ]* big.Int )
138
139
shares , err := elReader .GetOperatorShares (ctx , config .operatorAddress , config .strategyAddresses )
@@ -144,24 +145,43 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
144
145
}
145
146
146
147
/*
147
- 6. Using all of the above, calculate SlashableMagnitudeHolders object
148
- for displaying the allocation state of the operator
148
+ 6. Using all of the above, get Slashable Shares for the operator
149
+ */
150
+ slashableSharesMap , err := getSlashableShares (
151
+ ctx ,
152
+ config .operatorAddress ,
153
+ registeredOperatorSets ,
154
+ config .strategyAddresses ,
155
+ elReader ,
156
+ )
157
+ if err != nil {
158
+ return eigenSdkUtils .WrapError ("failed to get slashable shares" , err )
159
+ }
160
+
161
+ /*
162
+ 7. Using all of the above, calculate SlashableMagnitudeHolders object
163
+ for displaying the allocation state of the operator
149
164
*/
150
165
slashableMagnitudeHolders := make (SlashableMagnitudeHolders , 0 )
151
166
dergisteredOpsets := make (DeregsiteredOperatorSets , 0 )
152
167
for strategy , allocations := range allAllocations {
153
168
logger .Debugf ("Strategy: %s, Allocations: %v" , strategy , allocations )
154
169
strategyShares := operatorDelegatedSharesMap [strategy ]
170
+ totalMagnitude := totalMagnitudeMap [strategy ]
155
171
for _ , alloc := range allocations {
156
- currentShares , currentSharesPercentage := getSharesFromMagnitude (
157
- strategyShares ,
158
- alloc .CurrentMagnitude .Uint64 (),
159
- )
172
+ currentShares := slashableSharesMap [gethcommon .HexToAddress (strategy )][getUniqueKey (alloc .AvsAddress , alloc .OperatorSetId )]
173
+ currentSharesPercentage := getSharePercentage (currentShares , strategyShares )
174
+
160
175
newMagnitudeBigInt := big .NewInt (0 )
161
176
if alloc .PendingDiff .Cmp (big .NewInt (0 )) != 0 {
162
177
newMagnitudeBigInt = big .NewInt (0 ).Add (alloc .CurrentMagnitude , alloc .PendingDiff )
163
178
}
164
- newShares , newSharesPercentage := getSharesFromMagnitude (strategyShares , newMagnitudeBigInt .Uint64 ())
179
+
180
+ newShares , newSharesPercentage := getSharesFromMagnitude (
181
+ strategyShares ,
182
+ newMagnitudeBigInt .Uint64 (),
183
+ totalMagnitude ,
184
+ )
165
185
166
186
// Check if the operator set is not registered and add it to the unregistered list
167
187
// Then skip the rest of the loop
@@ -235,36 +255,65 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
235
255
return nil
236
256
}
237
257
238
- func getSharesFromMagnitude (totalScaledShare * big.Int , magnitude uint64 ) (* big.Int , * big.Float ) {
258
+ func getSharePercentage (shares * big.Int , totalShares * big.Int ) * big.Float {
259
+ percentageShares := big .NewInt (1 )
260
+ percentageShares = percentageShares .Mul (shares , big .NewInt (100 ))
261
+ percentageSharesFloat := new (
262
+ big.Float ,
263
+ ).Quo (new (big.Float ).SetInt (percentageShares ), new (big.Float ).SetInt (totalShares ))
264
+ return percentageSharesFloat
265
+ }
266
+
267
+ func getSlashableShares (
268
+ ctx context.Context ,
269
+ operatorAddress gethcommon.Address ,
270
+ opSets []allocationmanager.OperatorSet ,
271
+ strategyAddresses []gethcommon.Address ,
272
+ reader elChainReader ,
273
+ ) (map [gethcommon.Address ]map [string ]* big.Int , error ) {
274
+ result := make (map [gethcommon.Address ]map [string ]* big.Int )
275
+ for _ , opSet := range opSets {
276
+ slashableSharesMap , err := reader .GetSlashableShares (ctx , operatorAddress , opSet , strategyAddresses )
277
+ if err != nil {
278
+ return nil , err
279
+ }
239
280
281
+ for strat , shares := range slashableSharesMap {
282
+ if _ , ok := result [strat ]; ! ok {
283
+ result [strat ] = make (map [string ]* big.Int )
284
+ }
285
+ result [strat ][getUniqueKey (opSet .Avs , opSet .Id )] = shares
286
+ }
287
+ }
288
+ return result , nil
289
+ }
290
+
291
+ func getSharesFromMagnitude (totalShare * big.Int , magnitude uint64 , totalMagnitude uint64 ) (* big.Int , * big.Float ) {
240
292
/*
241
- * shares = totalScaledShare * magnitude / PrecisionFactor
242
- * percentageShares = (shares / totalScaledShare ) * 100
293
+ * shares = totalShare * magnitude / totalMagnitude
294
+ * percentageShares = (shares / totalShare ) * 100
243
295
*/
244
296
// Check for zero magnitude or totalScaledShare to avoid divide-by-zero errors
245
- if magnitude == 0 || totalScaledShare .Cmp (big .NewInt (0 )) == 0 {
297
+ if magnitude == 0 || totalShare .Cmp (big .NewInt (0 )) == 0 {
246
298
return big .NewInt (0 ), big .NewFloat (0 )
247
299
}
248
300
249
- slashableMagBigInt := big .NewInt (1 )
250
- slashableMagBigInt = slashableMagBigInt .SetUint64 (magnitude )
251
-
252
- scaledOpShares := big .NewInt (1 )
253
- scaledOpShares = scaledOpShares .Set (totalScaledShare )
254
- scaledOpShares = scaledOpShares .Div (scaledOpShares , PrecisionFactor )
255
- shares := scaledOpShares .Mul (scaledOpShares , slashableMagBigInt )
301
+ opShares := big .NewInt (1 )
302
+ opShares = opShares .Set (totalShare )
303
+ shares := opShares .Mul (opShares , big .NewInt (int64 (magnitude )))
304
+ shares = shares .Div (shares , big .NewInt (int64 (totalMagnitude )))
256
305
257
306
percentageShares := big .NewInt (1 )
258
- percentageShares = percentageShares .Mul (scaledOpShares , big .NewInt (100 ))
307
+ percentageShares = percentageShares .Mul (opShares , big .NewInt (100 ))
259
308
percentageSharesFloat := new (
260
309
big.Float ,
261
- ).Quo (new (big.Float ).SetInt (percentageShares ), new (big.Float ).SetInt (totalScaledShare ))
310
+ ).Quo (new (big.Float ).SetInt (percentageShares ), new (big.Float ).SetInt (totalShare ))
262
311
263
312
return shares , percentageSharesFloat
264
313
}
265
314
266
- func getUniqueKey (strategyAddress gethcommon.Address , opSetId uint32 ) string {
267
- return fmt .Sprintf ("%s-%d" , strategyAddress .String (), opSetId )
315
+ func getUniqueKey (avsAddress gethcommon.Address , opSetId uint32 ) string {
316
+ return fmt .Sprintf ("%s-%d" , avsAddress .String (), opSetId )
268
317
}
269
318
270
319
func readAndValidateShowConfig (cCtx * cli.Context , logger * logging.Logger ) (* showConfig , error ) {
0 commit comments