yearn / yearn-vaults-v2-subgraph

26 stars 41 forks source link

Create spec for in-subgraph performance metrics #12

Open chriswessels opened 3 years ago

chriswessels commented 3 years ago

Performance tracking is a key component of the subgraph. There are two sources of performance data:

  1. In-contract yield oracles

Doggie has implemented yield oracles inside the contract, currently as 12 and 50 day exponential moving averages of APY. These values are present on the contract state and are easy to include within the VaultUpdate state snapshots in the subgraph schema. They are however already "aggregate" values, in the sense that they approximate historical returns over periods of time.

  1. Subgraph-computed performance metrics

Yield oracles are great, but with the subgraph we'll have all the granular underlying data to compute more (in quantity and sophistication) measures of performance. The underlying data will come from the StrategyReport events/entities, which can then be aggregated over to produce various measures of performance for both Strategies and Vaults.

We need to decide to what extent we leverage/include the in-contract yield-oracle data, vs computing that within the subgraph. Also, for data computed in the subgraph, it'd be good to have a specification of which metrics/measures we want to compute, and why. I'm not a finance guy, so not sure which measures are most valuable/important though.

chriswessels commented 3 years ago

Here's the implementation PR for the in-contract yield oracles: https://github.com/iearn-finance/yearn-vaults/pull/69 Doggie has indicated that he may want to refactor so that there's a single state variable that's a fixed array of EMA APYs of varying duration.

salazarguille commented 2 years ago

I have implemented some calculations for APYs in the entity StrategyReportResult (per strategy/report).

Based on the reports (for a given strategy), it calculates the percentual rate (PR) for the time between each report (current and previous), and based on that PR, it calculates the APR.

I also used this calculation to display the info in Yearn Watch.

Example:

https://yearn.watch/vault/0xE537B5cc158EB71037D4125BDD7538421981E6AA/strategy/0xbA9052141cEf06FD55733D23231c37Fc856CE6F4 (section Reports)

salazarguille commented 2 years ago

I think that implementation covers the goal for the task, but we could discuss more to improve it.

bsamuels453 commented 2 years ago

@salazarguille how about we clone yearn-exporter's apy calcs? https://github.com/yearn/yearn-exporter/blob/master/yearn/apy/v2.py#L114-L199

I'm working on a branch that should bring a lot of the subgraph's data fields in line with what yearn-exporter provides, should be pretty ez to include