|
1 | 1 | import logging |
2 | 2 | from bots.util import get_logs_by_names, round_num |
3 | | -from constants.addresses import BEAN_ADDR |
| 3 | +from constants.addresses import BEAN_ADDR, BEANSTALK_ADDR |
4 | 4 | from constants.config import SILO_TOKENS_MAP, WHITELISTED_WELLS |
5 | 5 | from data_access.contracts.beanstalk import BeanstalkClient |
6 | 6 | from data_access.contracts.eth_events import EthEventsClient, EventClientType |
@@ -48,22 +48,28 @@ def seasonal_gauge_str(sunrise_receipt): |
48 | 48 |
|
49 | 49 | def get_seasons_and_blocks(current_logs): |
50 | 50 | """Gets the season number and block associated with the current and previous season""" |
51 | | - season_client = EthEventsClient([EventClientType.SEASON]) |
52 | | - |
53 | 51 | evt_sunrise = get_logs_by_names(["Sunrise"], current_logs)[0] |
54 | 52 | current_season_number = evt_sunrise.args.season |
55 | 53 |
|
56 | | - prev_sunrise_txn = season_client.get_log_with_topics( |
57 | | - "Sunrise", |
58 | | - [Web3.toHex(Web3.toBytes(current_season_number - 1).rjust(32, b'\x00'))], |
59 | | - # Constrained the search range to work with rpc limits. |
60 | | - # In practice the previous sunrise txn will be within this block range. |
61 | | - evt_sunrise.blockNumber - 10000, |
62 | | - evt_sunrise.blockNumber - 1 |
63 | | - ) |
64 | | - evt_prev_sunrise = prev_sunrise_txn[0].logs[0] |
| 54 | + # Direct eth_getLogs call to find previous Sunrise event |
| 55 | + web3 = get_web3_instance() |
| 56 | + sunrise_signature = Web3.keccak(text="Sunrise(uint256)").hex() |
| 57 | + |
| 58 | + prev_sunrise_logs = web3.eth.get_logs({ |
| 59 | + 'address': BEANSTALK_ADDR, |
| 60 | + 'topics': [ |
| 61 | + sunrise_signature, |
| 62 | + Web3.toHex(Web3.toBytes(current_season_number - 1).rjust(32, b'\x00')) |
| 63 | + ], |
| 64 | + 'fromBlock': evt_sunrise.blockNumber - 10000, |
| 65 | + 'toBlock': evt_sunrise.blockNumber - 1 |
| 66 | + }) |
| 67 | + |
| 68 | + # Extract blockNumber directly from the raw log |
| 69 | + prev_sunrise_block = prev_sunrise_logs[0]['blockNumber'] |
| 70 | + |
65 | 71 | return { |
66 | | - "prev": { "season": current_season_number-1, "block": evt_prev_sunrise.blockNumber }, |
| 72 | + "prev": { "season": current_season_number-1, "block": prev_sunrise_block }, |
67 | 73 | "current": { "season": current_season_number, "block": evt_sunrise.blockNumber }, |
68 | 74 | } |
69 | 75 |
|
|
0 commit comments