Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Premium apy is wrongly calculated when updates happen #60

Open
Evert0x opened this issue Sep 4, 2022 · 0 comments
Open

Premium apy is wrongly calculated when updates happen #60

Evert0x opened this issue Sep 4, 2022 · 0 comments

Comments

@Evert0x
Copy link
Contributor

Evert0x commented Sep 4, 2022

When the calc_apy functions runs it uses the current sum_of_premiums to calculate the premiums_apy.

premiums_per_second = ProtocolPremium.get_sum_of_premiums(session)
incentives_per_second = ProtocolPremium.get_usdc_incentive_premiums(session)
# Incentives are included in the total premiums, exclude them here
if premiums_per_second is not None and incentives_per_second is not None:
premiums_per_second -= incentives_per_second
premiums_apy = get_premiums_apy(tvl.value, premiums_per_second) if premiums_per_second else 0

This will result in the wrong premiums_apy if one of the premiums have been updated during the last time it ran, which could result in triggering this edge case (which technically should not be possible)

if premiums_apy > indx.apy:
logger.warning("Premiums APY %s is being skipped beacuse it is higher than the total APY.")

How does this happen?

For example, the calc_apy function runs every 24 hours (t=0, t=24, t=48, ..)

t=0 --> tvl=365.000, premiums_per_second=200 which results in 2% APY. (20 USDC yield per day)
t=23.99 --> premiums_per_second=400 which results in 4% APY
t=24 --> tvl=365.020 , premiums_per_second=400 which results in 4% APY

^ on t=24 the yield is ~2% but the premiums_apy = 4%, causing the edge case to hit.

Solution

Would include the removal of these checks

if premiums_apy > indx.apy:
logger.warning("Premiums APY %s is being skipped beacuse it is higher than the total APY.")
else:
indx.premiums_apy = premiums_apy
if incentives_apy > indx.apy:
logger.warning("Incentive APY %s is being skipped beacuse it is higher than the total APY.")
else:
indx.incentives_apy = incentives_apy

Potential options

  1. Take into account the weighted premiums_per_second based on recent updates and use the same code structure, so in the example above it would use premiums_per_second=201 for example.
  2. Calculate apy every time a protocol premium is updated
  3. Split apy,premium_apy,incentives_apy in different functions but potentially calculate them against different TVLs?
  4. ..?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant