Change to max_route_length to make the logic clearer
This commit is contained in:
parent
4e9ff10988
commit
bb94eba02a
@ -92,19 +92,19 @@ def _get_shortest_route(
|
|||||||
start_swap: Swap,
|
start_swap: Swap,
|
||||||
end_swaps: List[Swap],
|
end_swaps: List[Swap],
|
||||||
all_swaps: List[Swap],
|
all_swaps: List[Swap],
|
||||||
shortest_route_length: Optional[int] = None,
|
max_route_length: Optional[int] = None,
|
||||||
) -> Optional[List[Swap]]:
|
) -> Optional[List[Swap]]:
|
||||||
if len(end_swaps) == 0:
|
if len(end_swaps) == 0:
|
||||||
return None
|
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
|
return None
|
||||||
|
|
||||||
for end_swap in end_swaps:
|
for end_swap in end_swaps:
|
||||||
if start_swap.token_out_address == end_swap.token_in_address:
|
if start_swap.token_out_address == end_swap.token_in_address:
|
||||||
return [start_swap, end_swap]
|
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
|
return None
|
||||||
|
|
||||||
other_swaps = [
|
other_swaps = [
|
||||||
@ -115,8 +115,8 @@ def _get_shortest_route(
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
shortest_remaining_route = None
|
shortest_remaining_route = None
|
||||||
shortest_remaining_route_length = (
|
max_remaining_route_length = (
|
||||||
None if shortest_route_length is None else shortest_route_length - 1
|
None if max_route_length is None else max_route_length - 1
|
||||||
)
|
)
|
||||||
|
|
||||||
for next_swap in other_swaps:
|
for next_swap in other_swaps:
|
||||||
@ -129,7 +129,7 @@ def _get_shortest_route(
|
|||||||
next_swap,
|
next_swap,
|
||||||
end_swaps,
|
end_swaps,
|
||||||
other_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 (
|
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)
|
or len(shortest_from_next) < len(shortest_remaining_route)
|
||||||
):
|
):
|
||||||
shortest_remaining_route = shortest_from_next
|
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:
|
if shortest_remaining_route is None:
|
||||||
return None
|
return None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user