Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Staking APR on 0x.org/zrx pools table #366

Open
mintcloud opened this issue Jan 31, 2021 · 0 comments
Open

Staking APR on 0x.org/zrx pools table #366

mintcloud opened this issue Jan 31, 2021 · 0 comments

Comments

@mintcloud
Copy link
Contributor

mintcloud commented Jan 31, 2021

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

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

  • memberZrxStaked by epoch {[epochId: 49, memberZrxStaked], [epochId: 50: memberZrxStaked], ...[epochId: eid-1, memberZrxStaked]} --> * needs to be added in endpoint
  • membersRewardsPaidInEth by 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:

  1. 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
  2. Fetch last ETH price
  3. Use ZRX price at the beginning of the current epoch
  4. 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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@mintcloud and others