Change to max_route_length to make the logic clearer

This commit is contained in:
Luke Van Seters 2022-01-03 16:09:34 -05:00
parent 4e9ff10988
commit bb94eba02a

View File

@ -92,19 +92,19 @@ def _get_shortest_route(
start_swap: Swap,
end_swaps: List[Swap],
all_swaps: List[Swap],
shortest_route_length: Optional[int] = None,
max_route_length: Optional[int] = None,
) -> Optional[List[Swap]]:
if len(end_swaps) == 0:
return None
if shortest_route_length is not None and shortest_route_length <= 2:
if max_route_length is not None and max_route_length < 2:
return None
for end_swap in end_swaps:
if start_swap.token_out_address == end_swap.token_in_address:
return [start_swap, end_swap]
if shortest_route_length is not None and shortest_route_length == 3:
if max_route_length is not None and max_route_length == 2:
return None
other_swaps = [
@ -115,8 +115,8 @@ def _get_shortest_route(
return None
shortest_remaining_route = None
shortest_remaining_route_length = (
None if shortest_route_length is None else shortest_route_length - 1
max_remaining_route_length = (
None if max_route_length is None else max_route_length - 1
)
for next_swap in other_swaps:
@ -129,7 +129,7 @@ def _get_shortest_route(
next_swap,
end_swaps,
other_swaps,
shortest_route_length=shortest_remaining_route_length,
max_route_length=max_remaining_route_length,
)
if shortest_from_next is not None and (
@ -137,7 +137,7 @@ def _get_shortest_route(
or len(shortest_from_next) < len(shortest_remaining_route)
):
shortest_remaining_route = shortest_from_next
shortest_remaining_route_length = len(shortest_from_next)
max_remaining_route_length = len(shortest_from_next) - 1
if shortest_remaining_route is None:
return None