From 69cad7537e8d3659a4c2fb4d4118a69b6e4ff667 Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Fri, 7 Jan 2022 12:22:45 -0500 Subject: [PATCH] Break swap outs / ins check into a function --- mev_inspect/arbitrages.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mev_inspect/arbitrages.py b/mev_inspect/arbitrages.py index fe3491b..46c607d 100644 --- a/mev_inspect/arbitrages.py +++ b/mev_inspect/arbitrages.py @@ -120,11 +120,7 @@ def _get_shortest_route( ) for next_swap in other_swaps: - if start_swap.token_out_address == next_swap.token_in_address and ( - start_swap.contract_address == next_swap.from_address - or start_swap.to_address == next_swap.contract_address - or start_swap.to_address == next_swap.from_address - ): + if _swap_outs_match_swap_ins(start_swap, next_swap): shortest_from_next = _get_shortest_route( next_swap, end_swaps, @@ -174,3 +170,11 @@ def _get_all_start_end_swaps(swaps: List[Swap]) -> List[Tuple[Swap, List[Swap]]] valid_start_ends.append((potential_start_swap, ends_for_start)) return valid_start_ends + + +def _swap_outs_match_swap_ins(swap_out, swap_in) -> bool: + return swap_out.token_out_address == swap_in.token_in_address and ( + swap_out.contract_address == swap_in.from_address + or swap_out.to_address == swap_in.contract_address + or swap_out.to_address == swap_in.from_address + )