-
Notifications
You must be signed in to change notification settings - Fork 55
Description
Propose to change the Average Rewards Shared column with the Average APR (last 3 epochs)
The proposed approach here calculates the APR client side, using staking API
Missing data point on Staking API : historical memberZrxStaked per epoch per pool necessary for calculation *
example
https://api.0x.org/staking/pools/23 -> allTimeStats -> memberZrxStaked (together with totalRewardsPaidInEth,membersRewardsPaidInEth..., indexed by epoch)
Endpoints used in calculation
- https://api.0x.org/staking/epochs
- https://api.0x.org/staking/epochs/X
- https://api.0x.org/staking/pool/Y
- Cryptocompare price APIs for ETH and ZRX
Algo
Assume we want to calculate average across N=5 epochs
Assume current epochId = eid = 54
Pull start date of every epoch from eid - N (loop through https://api.0x.org/staking/epochs/X)
{{[epochId: 49, epochStart: timestamp], [epochId: 50, epochStart: timestamp]...[epochId: 53, epochStart: timestamp]}
For each Pool Y
From https://api.0x.org/staking/pool/Y, pull last N data points of
memberZrxStakedby epoch{[epochId: 49, memberZrxStaked], [epochId: 50: memberZrxStaked], ...[epochId: eid-1, memberZrxStaked]}--> * needs to be added in endpointmembersRewardsPaidInEthby epoch{[epochId: 51, membersRewardsPaidInEth], [epochId: 52, membersRewardsPaidInEth], ...[epochId: eid-1, membersRewardsPaidInEth]}
Pull ZRX and ETH prices for every epochStart (day closure price seems fine).
{[epochId: 49, ZRX, ETH], [epochId: 50, ZRX, ETH], ...[epochId: eid-1, ZRX, ETH]}
Now it's possible to compute the APR per epoch per pool
APR_e_p = (membersRewardsPaidInEth * ETH / memberZrxStaked * ZRX )_e_p * (365 / epoch_length)
Can assume epoch_length = 7. Could be using the difference of the epoch start/end to generalize
It's now possible compute average per pool over N epochs.
Variations
The approach above excludes the current epoch.
Adding the current epoch APR can introduce strong fluctuations at the beginning of an epoch, as it requires estimating earnings on the fly and that can change dramatically with pool saturation.
What could be used alternatively for that would be the sevenDayProtocolFeesGeneratedInEth field, which should progressively match the actual value, but smoothens out the beginning of an epoch.
Algo for current epoch APR:
- Fetch
nextEpochStats -> memberZrxStaked(it's fixed during the epoch, and that's what used for calculations. Could use currentEpoch alternatively, but it will not show the effect of new/churned stake) from https://api.0x.org/staking/pools/X - Fetch last ETH price
- Use ZRX price at the beginning of the current epoch
APR_currentepoch_p = ( sevenDayProtocolFeesGeneratedInEth * ETH / memberZrxStaked * ZRX )_p * (365 / epoch_length)
Would suggest averaging past N APRs with current epoch APR for best-smoothened result