Skip to content

Commit

Permalink
update logic to be in wei
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrower95 committed Aug 20, 2024
1 parent e2ccdaf commit 6d5873f
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions cli/core/findStalePods.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func keys[A comparable, B any](coll map[A]B) []A {
}

type PodOwnerShare struct {
Shares uint64
ExecutionLayerBalance phase0.Gwei
IsEigenpod bool
SharesWei uint64
ExecutionLayerBalanceWei uint64
IsEigenpod bool
}

const ACCEPTABLE_BALANCE_DEVIATION = float64(0.95)
Expand All @@ -64,9 +64,9 @@ func isEigenpod(eth *ethclient.Client, chainId uint64, eigenpodAddress string) (

// default to false
cache.PodOwnerShares[eigenpodAddress] = PodOwnerShare{
Shares: 0,
ExecutionLayerBalance: phase0.Gwei(0),
IsEigenpod: false,
SharesWei: 0,
ExecutionLayerBalanceWei: 0,
IsEigenpod: false,
}

podManAddress, ok := PodManagerContracts()[chainId]
Expand Down Expand Up @@ -113,9 +113,9 @@ func isEigenpod(eth *ethclient.Client, chainId uint64, eigenpodAddress string) (
// Simulate fetching from contracts
// Implement contract fetching logic here
cache.PodOwnerShares[eigenpodAddress] = PodOwnerShare{
Shares: podOwnerShares.Uint64(),
ExecutionLayerBalance: weiToGwei(balance.Uint64()),
IsEigenpod: true,
SharesWei: podOwnerShares.Uint64(),
ExecutionLayerBalanceWei: balance.Uint64(),
IsEigenpod: true,
}

return true, nil
Expand Down Expand Up @@ -219,7 +219,7 @@ func FindStaleEigenpods(ctx context.Context, eth *ethclient.Client, nodeUrl stri
return nil, err
}

totalAssetsGweiByEigenpod := utils.Reduce(keys(slashedEigenpods), func(allBalances map[string]phase0.Gwei, eigenpod string) map[string]phase0.Gwei {
totalAssetsWeiByEigenpod := utils.Reduce(keys(slashedEigenpods), func(allBalances map[string]uint64, eigenpod string) map[string]uint64 {
// total assets of an eigenpod are determined as;
// SUM(
// - native ETH in the pod
Expand All @@ -230,25 +230,25 @@ func FindStaleEigenpods(ctx context.Context, eth *ethclient.Client, nodeUrl stri
return withdrawal != nil && strings.EqualFold(*withdrawal, eigenpod)
})

allValidatorBalancesSummed := utils.Reduce(allValidatorsForEigenpod, func(accum phase0.Gwei, validator ValidatorWithIndex) phase0.Gwei {
allValidatorBalancesSummedGwei := utils.Reduce(allValidatorsForEigenpod, func(accum phase0.Gwei, validator ValidatorWithIndex) phase0.Gwei {
return accum + allValidatorBalances[validator.Index]
}, phase0.Gwei(0))

allBalances[eigenpod] = phase0.Gwei(cache.PodOwnerShares[eigenpod].ExecutionLayerBalance) + allValidatorBalancesSummed
// converting gwei to wei
allBalances[eigenpod] = cache.PodOwnerShares[eigenpod].ExecutionLayerBalanceWei + (uint64(allValidatorBalancesSummedGwei) * params.GWei)
return allBalances
}, map[string]phase0.Gwei{})
}, map[string]uint64{})

if verbose {
log.Printf("%d EigenPods were slashed\n", len(slashedEigenpods))
}

unhealthyEigenpods := utils.Filter(keys(slashedEigenpods), func(eigenpod string) bool {
balance, ok := totalAssetsGweiByEigenpod[eigenpod]
balance, ok := totalAssetsWeiByEigenpod[eigenpod]
if !ok {
return false
}
executionBalance := cache.PodOwnerShares[eigenpod].Shares
if balance <= phase0.Gwei(float64(executionBalance)*ACCEPTABLE_BALANCE_DEVIATION) {
executionBalance := cache.PodOwnerShares[eigenpod].SharesWei
if balance <= uint64(float64(executionBalance)*ACCEPTABLE_BALANCE_DEVIATION) {
if verbose {
log.Printf("[%s] %.2f%% deviation (beacon: %d -> execution: %d)\n", eigenpod, 100*(float64(executionBalance)-float64(balance))/float64(executionBalance), balance, executionBalance)
}
Expand Down

0 comments on commit 6d5873f

Please sign in to comment.