Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
harisang committed Nov 22, 2024
1 parent 8111a6e commit d7f84dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/sync/batch_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Main Entry point for price feed sync"""
from dune_client.client import DuneClient
import web3

import os
from src.fetch.orderbook import OrderbookFetcher
from src.logger import set_log
from src.sync.config import BatchDataSyncConfig
Expand All @@ -20,11 +20,14 @@ async def sync_batch_data(
dry_run: bool,
) -> None:
"""Batch data Sync Logic"""
network = os.environ["NETWORK"]
if network == "mainnet":
network = "ethereum"
block_range_list, months_list = compute_block_and_month_range(node)
for i in range(len(block_range_list)):
start_block = block_range_list[i][0]
end_block = block_range_list[i][1]
table_name = "test_batch_rewards_ethereum_" + months_list[i]
table_name = config.table + "_" + network + "_" + months_list[i]
block_range = BlockRange(block_from=start_block, block_to=end_block)
log.info(
f"About to process block range ({start_block}, {end_block}) for month {months_list[i]}"
Expand All @@ -34,7 +37,7 @@ async def sync_batch_data(
if not dry_run:
dune.upload_csv(
data=batch_data.to_csv(index=False),
table_name=table_name, # config.table,
table_name=table_name,
description=config.description,
is_private=False,
)
Expand Down
8 changes: 5 additions & 3 deletions src/sync/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Shared methods between both sync scripts."""
from datetime import datetime, timezone
import time
from dateutil import tz
from web3 import Web3
from src.logger import set_log
from src.models.tables import SyncTable
Expand All @@ -23,7 +21,7 @@ def last_sync_block(aws: AWSClient, table: SyncTable, genesis_block: int = 0) ->
return block_from


def find_block_with_timestamp(node, time_stamp):
def find_block_with_timestamp(node, time_stamp) -> int:
"""
This implements binary search and returns the smallest block number
whose timestamp is at least as large as the time_stamp argument passed in the function
Expand Down Expand Up @@ -57,6 +55,10 @@ def find_block_with_timestamp(node, time_stamp):


def compute_block_and_month_range(node: Web3):
"""
This determines the block range and the relevant months
for which we will compute and upload data on Dune.
"""
# We first compute the relevant block range
# Here, we assume that the job runs at least once every 24h
# Because of that, if it is the first day of month, we also
Expand Down

0 comments on commit d7f84dd

Please sign in to comment.