Skip to content

Commit

Permalink
feat: raise ApyError for egrigious numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored and 0xBasically committed Aug 10, 2023
1 parent 625346c commit c0417e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions yearn/apy/balancer/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ async def calculate_simple(vault, gauge: Gauge, samples: ApySamples) -> Apy:
pool_token_price,
block=now
)
if apr_data.bal_apr > 1000 or apr_data.aura_apr > 1000:
raise ApyError('aura', f'apr data too big {apr_data}')

gross_apr = apr_data.gross_apr * apr_data.debt_ratio

Expand Down
10 changes: 9 additions & 1 deletion yearn/apy/curve/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ async def calculate_simple(vault, gauge: Gauge, samples: ApySamples) -> Apy:
if time() > reward_data['period_finish']:
pool_price = 1

base_apr = gauge.calculate_base_apr(MAX_BOOST, crv_price, pool_price, base_asset_price)
base_apr = gauge.calculate_base_apr(BOOST[chain.id], crv_price, pool_price, base_asset_price)
if base_apr > 1000:
raise ApyError('crv', f'base apr too high: {base_apr}', f'MAX BOOST: {MAX_BOOST} crv price: {crv_price} pool price: {pool_price} base asset price: {base_asset_price}')

voter_proxy = addresses[chain.id]['yearn_voter_proxy'] if chain.id in addresses else None
y_boost = await gauge.calculate_boost(BOOST[chain.id], voter_proxy, block)

Expand Down Expand Up @@ -301,9 +304,14 @@ async def calculate_simple(vault, gauge: Gauge, samples: ApySamples) -> Apy:
crv_debt_ratio = 1

crv_apr = base_apr * y_boost + reward_apr
if crv_apr > 1000:
raise ApyError('crv', f'crv apr too high: {crv_apr}', f'base apr: {base_apr} yboost: {y_boost} reward apr: {reward_apr}')

crv_apr_minus_keep_crv = base_apr * y_boost * (1 - crv_keep_crv)

gross_apr = (1 + (crv_apr * crv_debt_ratio + cvx_apy_data.cvx_apr * cvx_apy_data.cvx_debt_ratio)) * (1 + pool_apy) - 1
if gross_apr > 1000:
raise ApyError('crv', f'gross apr too high: {gross_apr}', f'crv apr: {crv_apr} crv debt ratio: {crv_debt_ratio} cvx apr: {cvx_apy_data.cvx_apr} cvx debt ratio: {cvx_apy_data.cvx_debt_ratio} pool apy: {pool_apy}')

cvx_net_apr = (cvx_apy_data.cvx_apr_minus_keep_crv + cvx_apy_data.convex_reward_apr) * (1 - performance) - management
cvx_net_farmed_apy = (1 + (cvx_net_apr / COMPOUNDING)) ** COMPOUNDING - 1
Expand Down

0 comments on commit c0417e3

Please sign in to comment.