EmerisHQ / demeris

Emeris web app
https://app.emeris.com/
Apache License 2.0
12 stars 2 forks source link

Add APY pool calculation #399

Open gamarin2 opened 3 years ago

gamarin2 commented 3 years ago

Pool APY can be calculated using the following formula:

APY = (Value of swap fee for last 1 hour) / (Total value of pool(TVL)) * 24 * 365 

Value of swap fee can be obtained via this endpoint https://github.com/allinbits/demeris-backend/pull/105 It comes in both denoms of the pool

TVL is just reserve balances

So basically `(swapFeeCoin0ps + swapFeeCoin1) / (reserveBalanceCoin0ps + reserveBalanceCoin1) 24 365

where ps is the poolprice such that coin0*ps = coin1

nylira commented 3 years ago

Is swap fee for the last hour too fine grained? I guess it's okay to start with. For greater APY stability I could see us going to swap fees for one day or even swap fees for 7 days.

clockworkgr commented 3 years ago

Is swap fee for the last hour too fine grained? I guess it's okay to start with. For greater APY stability I could see us going to swap fees for one day or even swap fees for 7 days.

the problem is that we only get swapFees from the API .... to calculate APY we use TVL at that instance

last hour is too fine-grained (at least 1d would be representative of fees accrued) but TVL at a single instance for a whole days worth of fees is the opposite...

Ideally (and I raised the issue in slack) , APY should be calculated on the backend and cached....then we can construct a moving average from that and serve this on the API