Skip to content

Commit

Permalink
fixes after the review
Browse files Browse the repository at this point in the history
  • Loading branch information
kgarbacinski committed Feb 21, 2024
1 parent 1420926 commit b4df2de
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_bitquery_header():
headers = {
"Content-Type": "application/json",
"X-API-KEY": app.config["BITQUERY_API_KEY"],
"Authorization": "Bearer ory_at_yeIAwzWgtkssnWzCCpDKnrDv74AEkhaRbO1VHsrCSz0.nVnX2zUQiYr2AKSu823GYOuyIsiyVyp5WLDBFcawQT8",
"Authorization": app.config["BITQUERY_BEARER"],
}

return headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def get_block_num_from_ts(timestamp: int) -> int:
app.logger.debug(f"Getting block number from timestamp: {timestamp}")
api_url = _get_api_url(timestamp, BlockAction.BLOCK_TS)
api_url = _get_api_url(timestamp, BlockAction.BLOCK_NO_BY_TS)
try:
response = requests.get(api_url)
raise_for_status(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AccountAction(StrEnum):


class BlockAction(StrEnum):
BLOCK_TS = "getblocknobytime"
BLOCK_NO_BY_TS = "getblocknobytime"
BLOCK_REWARD = "getblockreward"


Expand Down
30 changes: 21 additions & 9 deletions backend/app/modules/staking/proceeds/service/aggregated.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@


class AggregatedStakingProceeds(Model):
def _compute_blocks_reward(
self, start_sec: int, end_sec: int, withdrawals_target: str
) -> int:
blocks_reward = 0

if end_sec is None:
return blocks_reward

start_datetime, end_datetime = (
timestamp_to_isoformat(start_sec),
timestamp_to_isoformat(end_sec),
)

blocks_reward = get_blocks_reward(
withdrawals_target, start_datetime, end_datetime
)
return blocks_reward

def get_staking_proceeds(self, context: Context) -> int:
"""
Retrieves a list of transactions, calculates MEV value and aggregates it with withdrawals.
Expand Down Expand Up @@ -52,15 +70,9 @@ def get_staking_proceeds(self, context: Context) -> int:
withdrawals_value = sum_withdrawals(withdrawals)

start_sec, end_sec = context.epoch_details.duration_range
blocks_reward = 0
if end_sec is not None:
start_datetime, end_datetime = (
timestamp_to_isoformat(start_sec),
timestamp_to_isoformat(end_sec),
)

blocks_reward = get_blocks_reward(
withdrawals_target, start_datetime, end_datetime
)
blocks_reward = self._compute_blocks_reward(
start_sec, end_sec, withdrawals_target
)

return aggregate_proceeds(mev_value, withdrawals_value, blocks_reward)
1 change: 1 addition & 0 deletions backend/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Config(object):
WEB3_PROVIDER = Web3.HTTPProvider(os.getenv("ETH_RPC_PROVIDER_URL"))
ETHERSCAN_API_KEY = os.getenv("ETHERSCAN_API_KEY")
BITQUERY_API_KEY = os.getenv("BITQUERY_API_KEY")
BITQUERY_BEARER = os.getenv("BITQUERY_BEARER")
SCHEDULER_ENABLED = _parse_bool(os.getenv("SCHEDULER_ENABLED"))
CACHE_TYPE = "SimpleCache"

Expand Down

0 comments on commit b4df2de

Please sign in to comment.