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

fix daily apy #376

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions eagleproject/core/blockchain/harvest/transaction_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
explode_log_data
)
from core.blockchain.harvest.snapshots import (
build_asset_block
build_asset_block,
latest_snapshot_block_number
)
from core.blockchain.rpc import (
creditsBalanceOf,
Expand Down Expand Up @@ -744,6 +745,24 @@ def backfill_subscribers():
sub.save()


def get_block_time_from_block_number(number):
result = Block.objects.filter(block_number__gte=number).order_by('block_time')[:1]

if len(result) != 1:
raise Exception('Can not find block time for block number', START_OF_PROJECT)

return result[0].block_time


def backfill_daily_stats(project=OriginTokens.OUSD):
START_OF_PROJECT = START_OF_OUSD_V2 if project == OriginTokens.OUSD else START_OF_OETH
start_time = get_block_time_from_block_number(START_OF_PROJECT)
latest_time = get_block_time_from_block_number(latest_snapshot_block_number(project))
days = (latest_time - start_time).days
_daily_rows(int(days), latest_snapshot_block_number(project), project=project)
return


# get all accounts that at some point held OUSD
def fetch_all_holders(project=OriginTokens.OUSD):
to_addresses = list(map(lambda log: log['to_address'], TokenTransfer.objects.filter(project=project).values('to_address').distinct()))
Expand Down Expand Up @@ -1640,7 +1659,7 @@ def _daily_rows(steps, latest_block_number, project, start_at=0):


s.apr = (
Decimal(100) * change * (Decimal(365) * BLOCKS_PER_DAY) / blocks
Decimal(100) * change * Decimal(365)
sparrowDom marked this conversation as resolved.
Show resolved Hide resolved
)
s.apy = to_apy(s.apr, 1)

Expand Down
5 changes: 5 additions & 0 deletions eagleproject/scripts/backfill_daily_stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from core.blockchain.harvest.transaction_history import backfill_daily_stats

def run(*script_args):
project = script_args[0] if len(script_args) > 0 else None
backfill_daily_stats(project)