From c0417e3afe9a068f97017ec984386f65c7914d49 Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 1 Aug 2023 21:30:06 +0000 Subject: [PATCH] feat: raise ApyError for egrigious numbers --- yearn/apy/balancer/simple.py | 2 ++ yearn/apy/curve/simple.py | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/yearn/apy/balancer/simple.py b/yearn/apy/balancer/simple.py index ea0cc1633..d232e0db3 100644 --- a/yearn/apy/balancer/simple.py +++ b/yearn/apy/balancer/simple.py @@ -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 diff --git a/yearn/apy/curve/simple.py b/yearn/apy/curve/simple.py index 711f09474..03f5f52d7 100644 --- a/yearn/apy/curve/simple.py +++ b/yearn/apy/curve/simple.py @@ -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) @@ -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