Calculations for Consensus Layer APR
Another important task is calculating a validator’s live Consensus layer APR on every epoch while simultaneously adjusting its historical earnings from the validator activation epoch. At the end of every epoch, we receive the validator’s balance and can see its change relative to the previous epoch. After every epoch, we update the cumulative earnings for each validator and calculate the APR. This way we get the live APR for each validator which in turn gives the APR for each index. At the end of each epoch, the process of calculating APR and earnings looks like this:
The formula used for the APR calculation is:
The Ethereum Foundation script detail how to calculate consensus layer epochs per year. The average number of seconds in a year is defined to be 31556908.8 to identify and calculate eligible epochs in a year. Since each Consensus layer epoch has 32 slots and each slot takes 12 seconds to complete, the number of epochs in a year can be calculated as follows:
Using these formulas, we are able to calculate a validator’s dETH APR in real time after every epoch. We can also derive the APR of the indexes from the average APR of all the validators.