Skip to content

Commit

Permalink
Simplify pools_to_add_from_contracts from a list of tuples of5 elem…
Browse files Browse the repository at this point in the history
…ents to a "flat" list of elements
  • Loading branch information
barak manos committed May 26, 2024
1 parent 6fcb799 commit 4fa7161
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
9 changes: 2 additions & 7 deletions fastlane_bot/events/async_event_update_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def _process_contract_chunks(

def _get_pool_contracts(mgr: Any) -> List[Dict[str, Any]]:
contracts = []
for add, en, event, key, value in mgr.pools_to_add_from_contracts:
for event in mgr.pools_to_add_from_contracts:
exchange_name = mgr.exchange_name_from_event(event)
ex = mgr.exchanges[exchange_name]
abi = ex.get_abi()
Expand Down Expand Up @@ -323,11 +323,6 @@ def async_update_pools_from_contracts(mgr: Any, current_block: int):
orig_num_pools_in_data = len(mgr.pool_data)
mgr.cfg.logger.info("Async process now updating pools from contracts...")

all_events = [
event
for address, exchange_name, event, key, value in mgr.pools_to_add_from_contracts
]

# split contracts into chunks of 1000
contracts = _get_pool_contracts(mgr)
chunks = [contracts[i : i + 1000] for i in range(0, len(contracts), 1000)]
Expand Down Expand Up @@ -471,7 +466,7 @@ def async_update_pools_from_contracts(mgr: Any, current_block: int):
)

# update the pool_data from events
update_pools_from_events(-1, mgr, all_events)
update_pools_from_events(-1, mgr, mgr.pools_to_add_from_contracts)

mgr.cfg.logger.info(
f"Async Updating pools from contracts took {(time.time() - start_time):0.4f} seconds"
Expand Down
2 changes: 1 addition & 1 deletion fastlane_bot/events/managers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class BaseManager:
tokens: List[Dict[str, str]] = field(default_factory=dict)
target_tokens: List[str] = field(default_factory=list)
tenderly_fork_id: str = None
pools_to_add_from_contracts: List[Tuple[str, str, Any, str, str]] = field(
pools_to_add_from_contracts: List[Any] = field(
default_factory=list
)
exchange_start_blocks: Dict[str, int] = field(default_factory=dict)
Expand Down
9 changes: 3 additions & 6 deletions fastlane_bot/events/managers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def update_from_event(self, event: Event):
# StrategyCreated events get appended to this list to be processed in the async workflow (see main.py),
# to gather any currently unknown fee and token info. Then the event will be reprocessed in this method
# and the pool data liquidity will be updated at that time (second pass).
self.pools_to_add_from_contracts.append(
(addr, ex_name, event, key, key_value)
)
self.pools_to_add_from_contracts.append(event)
return

if "descr" not in pool_info:
Expand Down Expand Up @@ -246,8 +244,7 @@ def handle_trading_fee_updated(self):

def update_remaining_pools(self):
remaining_pools = []
all_events = [pool[2] for pool in self.pools_to_add_from_contracts]
for event in all_events:
for event in self.pools_to_add_from_contracts:
addr = self.web3.to_checksum_address(event.address)
ex_name = self.exchange_name_from_event(event)
if not ex_name:
Expand All @@ -258,7 +255,7 @@ def update_remaining_pools(self):
pool_info = self.get_pool_info(key, key_value, ex_name)

if not pool_info:
remaining_pools.append((addr, ex_name, event, key, key_value))
remaining_pools.append(event)

random.shuffle(remaining_pools)
self.pools_to_add_from_contracts = remaining_pools
3 changes: 1 addition & 2 deletions fastlane_bot/tests/test_036_Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_test_update_from_event_carbon_v1_update():
event = event_data['carbon_v1_event_update']

manager.update_from_event(Event.from_dict(event_create_for_update))
pools_to_add_from_contracts = [event[2].args['id'] for event in manager.pools_to_add_from_contracts]
pools_to_add_from_contracts = [event.args['id'] for event in manager.pools_to_add_from_contracts]

assert event['args']['id'] in pools_to_add_from_contracts

Expand Down Expand Up @@ -173,7 +173,6 @@ def test_test_update_from_event_carbon_v1_delete():
assert cid not in [pool['cid'] for pool in manager.pool_data]

manager.update_from_event(Event.from_dict(event))
assert cid in [p[-1] for p in manager.pools_to_add_from_contracts]
fake_pool_data = {
"address": event['address'],
"cid": cid,
Expand Down

0 comments on commit 4fa7161

Please sign in to comment.