Skip to content

Commit

Permalink
fix: do not update event mappings in read_only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
platonfloria committed May 22, 2024
1 parent c5e0205 commit eef8c6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
17 changes: 9 additions & 8 deletions fastlane_bot/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,17 +793,18 @@ def save_events_to_json(
mgr.cfg.logger.debug(f"[events.utils.save_events_to_json] Saved events to {path}")


def process_new_events(new_event_mappings, event_mappings, filename):
def process_new_events(new_event_mappings, event_mappings, filename, read_only):
# Update the manager's event mappings
event_mappings.update(new_event_mappings)

# Update the local event_mappings csvs
df = pd.DataFrame.from_dict(event_mappings, orient='index').reset_index()
if len(df)>0:
df.columns = ['address', 'exchange']
# if the csvs are always sorted then the diffs will be readable
df.sort_values(by=['exchange','address'], inplace=True)
df.to_csv(filename, index=False)
if not read_only:
# Update the local event_mappings csvs
df = pd.DataFrame.from_dict(event_mappings, orient='index').reset_index()
if len(df)>0:
df.columns = ['address', 'exchange']
# if the csvs are always sorted then the diffs will be readable
df.sort_values(by=['exchange','address'], inplace=True)
df.to_csv(filename, index=False)


def update_pools_from_events(n_jobs: int, mgr: Any, latest_events: List[Event]):
Expand Down
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,9 @@ def run(mgr, args, tenderly_uri=None) -> None:
if args.pool_finder_period > 0 and (loop_idx - 1) % args.pool_finder_period == 0:
mgr.cfg.logger.info(f"Searching for unsupported Carbon pairs.")
uni_v2, uni_v3, solidly_v2 = pool_finder.get_pools_for_unsupported_pairs(mgr.pool_data, arb_mode=args.arb_mode)
process_new_events(uni_v2, mgr.uniswap_v2_event_mappings, f"fastlane_bot/data/blockchain_data/{args.blockchain}/uniswap_v2_event_mappings.csv")
process_new_events(uni_v3, mgr.uniswap_v3_event_mappings, f"fastlane_bot/data/blockchain_data/{args.blockchain}/uniswap_v3_event_mappings.csv")
process_new_events(solidly_v2, mgr.solidly_v2_event_mappings, f"fastlane_bot/data/blockchain_data/{args.blockchain}/solidly_v2_event_mappings.csv")
process_new_events(uni_v2, mgr.uniswap_v2_event_mappings, f"fastlane_bot/data/blockchain_data/{args.blockchain}/uniswap_v2_event_mappings.csv", args.read_only)
process_new_events(uni_v3, mgr.uniswap_v3_event_mappings, f"fastlane_bot/data/blockchain_data/{args.blockchain}/uniswap_v3_event_mappings.csv", args.read_only)
process_new_events(solidly_v2, mgr.solidly_v2_event_mappings, f"fastlane_bot/data/blockchain_data/{args.blockchain}/solidly_v2_event_mappings.csv", args.read_only)
handle_static_pools_update(mgr)
mgr.cfg.logger.info(f"Number of pools added: {len(uni_v2) + len(uni_v3) + len(solidly_v2)}")

Expand Down

0 comments on commit eef8c6c

Please sign in to comment.