Giveth / GIVeconomy

The Giveth Economy is the collective of projects, donors, builders, and community members builders that build the future of giving
GNU General Public License v3.0
6 stars 0 forks source link

API for fetching vault APY #877

Open divine-comedian opened 1 year ago

divine-comedian commented 1 year ago

We need to fetch the APY rates for the underlying vaults of the Beefy contracts

This is the relevant API documentation: https://docs.beefy.finance/developer-documentation/beefy-api#get-apy

image

We will need to fetch this APY daily for the correct vault we are using for the GIVsavings vault and add it to the historical APY to produce the APY graph The APY will be unique to each vault but not to each user.

subtracting fees

We can get the current fee % from the contract here: https://goerli-optimism.etherscan.io/address/0x799E7D9776c4A0392F6829DCB6BDc593d598F7AA#readProxyContract#F10 This returns for example 100000000000000000 in wei, so 0.1 or 10% fee on yield accrued.

To apply the fee to the APY we simply multiply the APY by 1- fee decimal | APY * (1 - fee) = feeAdjustedAPY

For example: APY = 5% fee = 10% (0.1)

5 * (1 - 0.1) = 4.5% The APY we calculate for subsequent use on graphs, calculations and UI would be 4.5%

The average APY to date can be calculated so:

  1. Record the APY for each day since inception.
  2. Sum up all the daily APYs.
  3. Divide the total by the number of days since inception to find the average daily APY.
  4. Multiply the result by 365 (or 366 in a leap year) to convert it to the average annual APY.

The APY table

The APY table can be calculated by graphing the daily APY rates along the y-axis and the period of time along the x-axis

divine-comedian commented 1 year ago

@mateodaza can you investigate how we can access and cache the API data?

@alireza-sharifpour JFYI

mateodaza commented 1 year ago

@mateodaza can you investigate how we can access and cache the API data?

@alireza-sharifpour JFYI

yeah man we can use something like redis for that, vercel just released something cool called vercel storage we could save the APY data in there and just upgrade when needed, it's not that complicated - all this through a serverless api function on the dapp