From 08d84be8873ea6b52e1b606ba0dac50fa0329239 Mon Sep 17 00:00:00 2001 From: rolandpo Date: Tue, 10 Oct 2023 13:18:33 +0200 Subject: [PATCH] add warnings for inaccurate intervals --- .../blockchain/harvest/transaction_history.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/eagleproject/core/blockchain/harvest/transaction_history.py b/eagleproject/core/blockchain/harvest/transaction_history.py index 02bc2fe..522191f 100644 --- a/eagleproject/core/blockchain/harvest/transaction_history.py +++ b/eagleproject/core/blockchain/harvest/transaction_history.py @@ -102,6 +102,8 @@ from core.coingecko import get_coin_history from core.defillama import get_stablecoin_market_cap +from core.logging import get_logger + import simplejson as json from django.core.exceptions import ObjectDoesNotExist @@ -109,6 +111,8 @@ from eth_abi import decode_single from eth_utils import decode_hex +log = get_logger(__name__) + ACCOUNT_ANALYZE_PARALLELISM=30 class rebase_log: @@ -1621,7 +1625,6 @@ def _daily_rows(steps, latest_block_number, project, start_at=0): block.block_time - timedelta(seconds=24 * 60 * 60) ).replace(tzinfo=timezone.utc) if last_snapshot: - contract_address = OUSD_VAULT if project == OriginTokens.OUSD else OETH_VAULT rebase_logs = get_rebase_logs(last_snapshot.block_number, block_number, project) @@ -1657,7 +1660,15 @@ def _daily_rows(steps, latest_block_number, project, start_at=0): # other_change = 1 - (s.rebasing_credits_per_token / last_snapshot.rebasing_credits_per_token) change = Decimal(sum(event['amount'] for event in s.rebase_events)) / (s.computed_supply - s.non_rebasing_supply) - + if change: + interval = block.block_time - last_snapshot.block_time + if (interval.total_seconds() > 90000): + log.warning("{}: daily stats interval too long ({})".format(last_snapshot.block_time, interval)) + elif (interval.total_seconds() < 82800): + log.warning("{}: daily stats interval too short ({})".format(last_snapshot.block_time, interval)) + + # apr based on cumulative yield from yield events taken after block.block_time, and before next snapshot + # the number of blocks in this period doesn't matter, as calculation includes all yield events in 24h period s.apr = ( Decimal(100) * change * Decimal(365) )