From 154d35662171106f9caccc348252f053127ca96f Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Wed, 22 Dec 2021 09:07:46 -0500 Subject: [PATCH 1/9] Only keep the longest arb --- mev_inspect/arbitrages.py | 66 +++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/mev_inspect/arbitrages.py b/mev_inspect/arbitrages.py index 786fbd8..bd4fb69 100644 --- a/mev_inspect/arbitrages.py +++ b/mev_inspect/arbitrages.py @@ -45,16 +45,37 @@ def _get_arbitrages_from_swaps(swaps: List[Swap]) -> List[Arbitrage]: if len(start_ends) == 0: return [] - # for (start, end) in filtered_start_ends: - for (start, end) in start_ends: - potential_intermediate_swaps = [ - swap for swap in swaps if swap is not start and swap is not end - ] - routes = _get_all_routes(start, end, potential_intermediate_swaps) + used_swaps = [] - for route in routes: - start_amount = route[0].token_in_amount - end_amount = route[-1].token_out_amount + for (start, ends) in start_ends: + if start in used_swaps: + continue + + longest_route = None + + for end in ends: + if end in used_swaps: + continue + + potential_intermediate_swaps = [ + swap + for swap in swaps + if (swap is not start and swap is not end and swap not in used_swaps) + ] + + routes = _get_all_routes( + start, + end, + potential_intermediate_swaps, + ) + + for route in routes: + if longest_route is None or len(route) > len(longest_route): + longest_route = route + + if longest_route is not None: + start_amount = longest_route[0].token_in_amount + end_amount = longest_route[-1].token_out_amount profit_amount = end_amount - start_amount error = None for swap in route: @@ -62,17 +83,20 @@ def _get_arbitrages_from_swaps(swaps: List[Swap]) -> List[Arbitrage]: error = swap.error arb = Arbitrage( - swaps=route, - block_number=route[0].block_number, - transaction_hash=route[0].transaction_hash, - account_address=route[0].from_address, - profit_token_address=route[0].token_in_address, + swaps=longest_route, + block_number=longest_route[0].block_number, + transaction_hash=longest_route[0].transaction_hash, + account_address=longest_route[0].from_address, + profit_token_address=longest_route[0].token_in_address, start_amount=start_amount, end_amount=end_amount, profit_amount=profit_amount, error=error, ) + all_arbitrages.append(arb) + used_swaps.extend(longest_route) + if len(all_arbitrages) == 1: return all_arbitrages else: @@ -83,7 +107,7 @@ def _get_arbitrages_from_swaps(swaps: List[Swap]) -> List[Arbitrage]: ] -def _get_all_start_end_swaps(swaps: List[Swap]) -> List[Tuple[Swap, Swap]]: +def _get_all_start_end_swaps(swaps: List[Swap]) -> List[Tuple[Swap, List[Swap]]]: """ Gets the set of all possible opening and closing swap pairs in an arbitrage via - swap[start].token_in == swap[end].token_out @@ -92,9 +116,12 @@ def _get_all_start_end_swaps(swaps: List[Swap]) -> List[Tuple[Swap, Swap]]: - not swap[end].to_address in all_pool_addresses """ pool_addrs = [swap.contract_address for swap in swaps] - valid_start_ends: List[Tuple[Swap, Swap]] = [] + valid_start_ends: List[Tuple[Swap, List[Swap]]] = [] + for index, potential_start_swap in enumerate(swaps): + ends_for_start = [] remaining_swaps = swaps[:index] + swaps[index + 1 :] + for potential_end_swap in remaining_swaps: if ( potential_start_swap.token_in_address @@ -102,7 +129,12 @@ def _get_all_start_end_swaps(swaps: List[Swap]) -> List[Tuple[Swap, Swap]]: and potential_start_swap.from_address == potential_end_swap.to_address and not potential_start_swap.from_address in pool_addrs ): - valid_start_ends.append((potential_start_swap, potential_end_swap)) + + ends_for_start.append(potential_end_swap) + + if len(ends_for_start) > 0: + valid_start_ends.append((potential_start_swap, ends_for_start)) + return valid_start_ends From 46f7786c4fb9f010cff4a6f28bdc2d079ee2a3e3 Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Wed, 22 Dec 2021 09:09:21 -0500 Subject: [PATCH 2/9] Only keep the shortest route instead --- mev_inspect/arbitrages.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mev_inspect/arbitrages.py b/mev_inspect/arbitrages.py index bd4fb69..7d7ba5e 100644 --- a/mev_inspect/arbitrages.py +++ b/mev_inspect/arbitrages.py @@ -51,7 +51,7 @@ def _get_arbitrages_from_swaps(swaps: List[Swap]) -> List[Arbitrage]: if start in used_swaps: continue - longest_route = None + shortest_route = None for end in ends: if end in used_swaps: @@ -70,12 +70,12 @@ def _get_arbitrages_from_swaps(swaps: List[Swap]) -> List[Arbitrage]: ) for route in routes: - if longest_route is None or len(route) > len(longest_route): - longest_route = route + if shortest_route is None or len(route) < len(shortest_route): + shortest_route = route - if longest_route is not None: - start_amount = longest_route[0].token_in_amount - end_amount = longest_route[-1].token_out_amount + if shortest_route is not None: + start_amount = shortest_route[0].token_in_amount + end_amount = shortest_route[-1].token_out_amount profit_amount = end_amount - start_amount error = None for swap in route: @@ -83,11 +83,11 @@ def _get_arbitrages_from_swaps(swaps: List[Swap]) -> List[Arbitrage]: error = swap.error arb = Arbitrage( - swaps=longest_route, - block_number=longest_route[0].block_number, - transaction_hash=longest_route[0].transaction_hash, - account_address=longest_route[0].from_address, - profit_token_address=longest_route[0].token_in_address, + swaps=shortest_route, + block_number=shortest_route[0].block_number, + transaction_hash=shortest_route[0].transaction_hash, + account_address=shortest_route[0].from_address, + profit_token_address=shortest_route[0].token_in_address, start_amount=start_amount, end_amount=end_amount, profit_amount=profit_amount, @@ -95,7 +95,7 @@ def _get_arbitrages_from_swaps(swaps: List[Swap]) -> List[Arbitrage]: ) all_arbitrages.append(arb) - used_swaps.extend(longest_route) + used_swaps.extend(shortest_route) if len(all_arbitrages) == 1: return all_arbitrages From 46b768c147997dafe41763091aa754d68f72d6a4 Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Wed, 22 Dec 2021 09:15:52 -0500 Subject: [PATCH 3/9] Break out shortest logic into a function --- mev_inspect/arbitrages.py | 85 +++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/mev_inspect/arbitrages.py b/mev_inspect/arbitrages.py index 7d7ba5e..5cedb7f 100644 --- a/mev_inspect/arbitrages.py +++ b/mev_inspect/arbitrages.py @@ -1,5 +1,5 @@ from itertools import groupby -from typing import List, Tuple +from typing import List, Optional, Tuple from mev_inspect.schemas.arbitrages import Arbitrage from mev_inspect.schemas.swaps import Swap @@ -45,37 +45,14 @@ def _get_arbitrages_from_swaps(swaps: List[Swap]) -> List[Arbitrage]: if len(start_ends) == 0: return [] - used_swaps = [] + used_swaps: List[Swap] = [] for (start, ends) in start_ends: - if start in used_swaps: - continue + route = _get_shortest_route_from_start(start, ends, swaps, used_swaps) - shortest_route = None - - for end in ends: - if end in used_swaps: - continue - - potential_intermediate_swaps = [ - swap - for swap in swaps - if (swap is not start and swap is not end and swap not in used_swaps) - ] - - routes = _get_all_routes( - start, - end, - potential_intermediate_swaps, - ) - - for route in routes: - if shortest_route is None or len(route) < len(shortest_route): - shortest_route = route - - if shortest_route is not None: - start_amount = shortest_route[0].token_in_amount - end_amount = shortest_route[-1].token_out_amount + if route is not None: + start_amount = route[0].token_in_amount + end_amount = route[-1].token_out_amount profit_amount = end_amount - start_amount error = None for swap in route: @@ -83,11 +60,11 @@ def _get_arbitrages_from_swaps(swaps: List[Swap]) -> List[Arbitrage]: error = swap.error arb = Arbitrage( - swaps=shortest_route, - block_number=shortest_route[0].block_number, - transaction_hash=shortest_route[0].transaction_hash, - account_address=shortest_route[0].from_address, - profit_token_address=shortest_route[0].token_in_address, + swaps=route, + block_number=route[0].block_number, + transaction_hash=route[0].transaction_hash, + account_address=route[0].from_address, + profit_token_address=route[0].token_in_address, start_amount=start_amount, end_amount=end_amount, profit_amount=profit_amount, @@ -95,7 +72,7 @@ def _get_arbitrages_from_swaps(swaps: List[Swap]) -> List[Arbitrage]: ) all_arbitrages.append(arb) - used_swaps.extend(shortest_route) + used_swaps.extend(route) if len(all_arbitrages) == 1: return all_arbitrages @@ -107,6 +84,44 @@ def _get_arbitrages_from_swaps(swaps: List[Swap]) -> List[Arbitrage]: ] +def _get_shortest_route_from_start( + start_swap: Swap, + end_swaps: List[Swap], + all_swaps: List[Swap], + used_swaps: List[Swap], +) -> Optional[List[Swap]]: + if start_swap in used_swaps: + return None + + shortest_route = None + + for end_swap in end_swaps: + if end_swap in used_swaps: + continue + + potential_intermediate_swaps = [ + swap + for swap in all_swaps + if ( + swap is not start_swap + and swap is not end_swap + and swap not in used_swaps + ) + ] + + routes = _get_all_routes( + start_swap, + end_swap, + potential_intermediate_swaps, + ) + + for route in routes: + if shortest_route is None or len(route) < len(shortest_route): + shortest_route = route + + return shortest_route + + def _get_all_start_end_swaps(swaps: List[Swap]) -> List[Tuple[Swap, List[Swap]]]: """ Gets the set of all possible opening and closing swap pairs in an arbitrage via From 17c9b835ac87265bf9a9365e6bcea6ac4dcb32dd Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Wed, 22 Dec 2021 10:26:26 -0500 Subject: [PATCH 4/9] Simplify smallest logic. Fix tests --- mev_inspect/arbitrages.py | 98 +++++++++++++++------------------------ tests/test_arbitrages.py | 52 +++++++++++++-------- 2 files changed, 70 insertions(+), 80 deletions(-) diff --git a/mev_inspect/arbitrages.py b/mev_inspect/arbitrages.py index 5cedb7f..2c7f158 100644 --- a/mev_inspect/arbitrages.py +++ b/mev_inspect/arbitrages.py @@ -48,7 +48,11 @@ def _get_arbitrages_from_swaps(swaps: List[Swap]) -> List[Arbitrage]: used_swaps: List[Swap] = [] for (start, ends) in start_ends: - route = _get_shortest_route_from_start(start, ends, swaps, used_swaps) + if start in used_swaps: + continue + + unused_ends = [end for end in ends if end not in used_swaps] + route = _get_shortest_route(start, unused_ends, swaps) if route is not None: start_amount = route[0].token_in_amount @@ -84,42 +88,47 @@ def _get_arbitrages_from_swaps(swaps: List[Swap]) -> List[Arbitrage]: ] -def _get_shortest_route_from_start( +def _get_shortest_route( start_swap: Swap, end_swaps: List[Swap], all_swaps: List[Swap], - used_swaps: List[Swap], ) -> Optional[List[Swap]]: - if start_swap in used_swaps: + # TODO - add max length + for end_swap in end_swaps: + if start_swap.token_out_address == end_swap.token_in_address: + return [start_swap, end_swap] + + other_swaps = [ + swap for swap in all_swaps if (swap is not start_swap and swap not in end_swaps) + ] + + if len(other_swaps) == 0: return None - shortest_route = None + shortest_route_rest = None - for end_swap in end_swaps: - if end_swap in used_swaps: - continue - - potential_intermediate_swaps = [ - swap - for swap in all_swaps - if ( - swap is not start_swap - and swap is not end_swap - and swap not in used_swaps + 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 + ): + shortest_from_next = _get_shortest_route( + next_swap, + end_swaps, + other_swaps, ) - ] - routes = _get_all_routes( - start_swap, - end_swap, - potential_intermediate_swaps, - ) + if shortest_from_next is not None and ( + shortest_route_rest is None + or len(shortest_from_next) < len(shortest_route_rest) + ): + shortest_route_rest = shortest_from_next - for route in routes: - if shortest_route is None or len(route) < len(shortest_route): - shortest_route = route - - return shortest_route + if shortest_route_rest is None: + return None + else: + return [start_swap] + shortest_route_rest def _get_all_start_end_swaps(swaps: List[Swap]) -> List[Tuple[Swap, List[Swap]]]: @@ -134,7 +143,7 @@ def _get_all_start_end_swaps(swaps: List[Swap]) -> List[Tuple[Swap, List[Swap]]] valid_start_ends: List[Tuple[Swap, List[Swap]]] = [] for index, potential_start_swap in enumerate(swaps): - ends_for_start = [] + ends_for_start: List[Swap] = [] remaining_swaps = swaps[:index] + swaps[index + 1 :] for potential_end_swap in remaining_swaps: @@ -151,36 +160,3 @@ 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 _get_all_routes( - start_swap: Swap, end_swap: Swap, other_swaps: List[Swap] -) -> List[List[Swap]]: - """ - Returns all routes (List[Swap]) from start to finish between a start_swap and an end_swap only accounting for token_address_in and token_address_out. - """ - # If the path is complete, return - if start_swap.token_out_address == end_swap.token_in_address: - return [[start_swap, end_swap]] - elif len(other_swaps) == 0: - return [] - - # Collect all potential next steps, check if valid, recursively find routes from next_step to end_swap - routes: List[List[Swap]] = [] - for potential_next_swap in other_swaps: - if start_swap.token_out_address == potential_next_swap.token_in_address and ( - start_swap.contract_address == potential_next_swap.from_address - or start_swap.to_address == potential_next_swap.contract_address - or start_swap.to_address == potential_next_swap.from_address - ): - remaining_swaps = [ - swap for swap in other_swaps if swap != potential_next_swap - ] - next_swap_routes = _get_all_routes( - potential_next_swap, end_swap, remaining_swaps - ) - if len(next_swap_routes) > 0: - for next_swap_route in next_swap_routes: - next_swap_route.insert(0, start_swap) - routes.append(next_swap_route) - return routes diff --git a/tests/test_arbitrages.py b/tests/test_arbitrages.py index 71bbc44..7be7b0f 100644 --- a/tests/test_arbitrages.py +++ b/tests/test_arbitrages.py @@ -1,6 +1,6 @@ from typing import List -from mev_inspect.arbitrages import _get_all_routes, get_arbitrages +from mev_inspect.arbitrages import _get_shortest_route, get_arbitrages from mev_inspect.classifiers.specs.uniswap import ( UNISWAP_V2_PAIR_ABI_NAME, UNISWAP_V3_POOL_ABI_NAME, @@ -171,39 +171,46 @@ def test_three_pool_arbitrage(get_transaction_hashes, get_addresses): assert arbitrage.profit_amount == first_token_out_amount - first_token_in_amount -def test_get_all_routes(): +def test_get_shortest_route(): # A -> B, B -> A start_swap = create_generic_swap("0xa", "0xb") end_swap = create_generic_swap("0xb", "0xa") - routes = _get_all_routes(start_swap, end_swap, []) - assert len(routes) == 1 + route = _get_shortest_route(start_swap, [end_swap], []) + assert route is not None + assert len(route) == 2 # A->B, B->C, C->A start_swap = create_generic_swap("0xa", "0xb") other_swaps = [create_generic_swap("0xb", "0xc")] end_swap = create_generic_swap("0xc", "0xa") - routes = _get_all_routes(start_swap, end_swap, other_swaps) - assert len(routes) == 1 + route = _get_shortest_route(start_swap, [end_swap], other_swaps) + assert route is not None + assert len(route) == 3 # A->B, B->C, C->A + A->D other_swaps.append(create_generic_swap("0xa", "0xd")) - routes = _get_all_routes(start_swap, end_swap, other_swaps) - assert len(routes) == 1 + route = _get_shortest_route(start_swap, [end_swap], other_swaps) + assert route is not None + assert len(route) == 3 # A->B, B->C, C->A + A->D B->E other_swaps.append(create_generic_swap("0xb", "0xe")) - routes = _get_all_routes(start_swap, end_swap, other_swaps) - assert len(routes) == 1 + route = _get_shortest_route(start_swap, [end_swap], other_swaps) + assert route is not None + assert len(route) == 3 # A->B, B->A, B->C, C->A other_swaps = [create_generic_swap("0xb", "0xa"), create_generic_swap("0xb", "0xc")] - routes = _get_all_routes(start_swap, end_swap, other_swaps) - assert len(routes) == 1 - expect_simple_route = [["0xa", "0xb"], ["0xb", "0xc"], ["0xc", "0xa"]] - assert len(routes[0]) == len(expect_simple_route) - for i in range(len(expect_simple_route)): - assert expect_simple_route[i][0] == routes[0][i].token_in_address - assert expect_simple_route[i][1] == routes[0][i].token_out_address + route = _get_shortest_route(start_swap, [end_swap], other_swaps) + expected_smallest_route = [["0xa", "0xb"], ["0xb", "0xc"], ["0xc", "0xa"]] + + assert route is not None + assert len(route) == len(expected_smallest_route) + for i, [expected_token_in, expected_token_out] in enumerate( + expected_smallest_route + ): + assert expected_token_in == route[i].token_in_address + assert expected_token_out == route[i].token_out_address # A->B, B->C, C->D, D->A, B->D end_swap = create_generic_swap("0xd", "0xa") @@ -212,8 +219,15 @@ def test_get_all_routes(): create_generic_swap("0xc", "0xd"), create_generic_swap("0xb", "0xd"), ] - routes = _get_all_routes(start_swap, end_swap, other_swaps) - assert len(routes) == 2 + expected_smallest_route = [["0xa", "0xb"], ["0xb", "0xd"], ["0xd", "0xa"]] + route = _get_shortest_route(start_swap, [end_swap], other_swaps) + assert len(route) == 3 + + for i, [expected_token_in, expected_token_out] in enumerate( + expected_smallest_route + ): + assert expected_token_in == route[i].token_in_address + assert expected_token_out == route[i].token_out_address def create_generic_swap( From 22769c952979eea8d26d74474e414024bb81ce5c Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Wed, 22 Dec 2021 10:38:22 -0500 Subject: [PATCH 5/9] Remove TODO - not needed for now --- mev_inspect/arbitrages.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mev_inspect/arbitrages.py b/mev_inspect/arbitrages.py index 2c7f158..b912d27 100644 --- a/mev_inspect/arbitrages.py +++ b/mev_inspect/arbitrages.py @@ -93,7 +93,6 @@ def _get_shortest_route( end_swaps: List[Swap], all_swaps: List[Swap], ) -> Optional[List[Swap]]: - # TODO - add max length for end_swap in end_swaps: if start_swap.token_out_address == end_swap.token_in_address: return [start_swap, end_swap] From ca921f896d7879aae218c172154f28de2c9988ff Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Wed, 22 Dec 2021 18:34:16 -0500 Subject: [PATCH 6/9] route => shortest_route in tests --- tests/test_arbitrages.py | 56 +++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/tests/test_arbitrages.py b/tests/test_arbitrages.py index 7be7b0f..1a321fa 100644 --- a/tests/test_arbitrages.py +++ b/tests/test_arbitrages.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Tuple from mev_inspect.arbitrages import _get_shortest_route, get_arbitrages from mev_inspect.classifiers.specs.uniswap import ( @@ -175,42 +175,37 @@ def test_get_shortest_route(): # A -> B, B -> A start_swap = create_generic_swap("0xa", "0xb") end_swap = create_generic_swap("0xb", "0xa") - route = _get_shortest_route(start_swap, [end_swap], []) - assert route is not None - assert len(route) == 2 + shortest_route = _get_shortest_route(start_swap, [end_swap], []) + assert shortest_route is not None + assert len(shortest_route) == 2 # A->B, B->C, C->A start_swap = create_generic_swap("0xa", "0xb") other_swaps = [create_generic_swap("0xb", "0xc")] end_swap = create_generic_swap("0xc", "0xa") - route = _get_shortest_route(start_swap, [end_swap], other_swaps) - assert route is not None - assert len(route) == 3 + shortest_route = _get_shortest_route(start_swap, [end_swap], other_swaps) + assert shortest_route is not None + assert len(shortest_route) == 3 # A->B, B->C, C->A + A->D other_swaps.append(create_generic_swap("0xa", "0xd")) - route = _get_shortest_route(start_swap, [end_swap], other_swaps) - assert route is not None - assert len(route) == 3 + shortest_route = _get_shortest_route(start_swap, [end_swap], other_swaps) + assert shortest_route is not None + assert len(shortest_route) == 3 # A->B, B->C, C->A + A->D B->E other_swaps.append(create_generic_swap("0xb", "0xe")) - route = _get_shortest_route(start_swap, [end_swap], other_swaps) - assert route is not None - assert len(route) == 3 + shortest_route = _get_shortest_route(start_swap, [end_swap], other_swaps) + assert shortest_route is not None + assert len(shortest_route) == 3 # A->B, B->A, B->C, C->A other_swaps = [create_generic_swap("0xb", "0xa"), create_generic_swap("0xb", "0xc")] - route = _get_shortest_route(start_swap, [end_swap], other_swaps) - expected_smallest_route = [["0xa", "0xb"], ["0xb", "0xc"], ["0xc", "0xa"]] + actual_shortest_route = _get_shortest_route(start_swap, [end_swap], other_swaps) + expected_shortest_route = [("0xa", "0xb"), ("0xb", "0xc"), ("0xc", "0xa")] - assert route is not None - assert len(route) == len(expected_smallest_route) - for i, [expected_token_in, expected_token_out] in enumerate( - expected_smallest_route - ): - assert expected_token_in == route[i].token_in_address - assert expected_token_out == route[i].token_out_address + assert actual_shortest_route is not None + _assert_route_tokens_equal(actual_shortest_route, expected_shortest_route) # A->B, B->C, C->D, D->A, B->D end_swap = create_generic_swap("0xd", "0xa") @@ -219,12 +214,21 @@ def test_get_shortest_route(): create_generic_swap("0xc", "0xd"), create_generic_swap("0xb", "0xd"), ] - expected_smallest_route = [["0xa", "0xb"], ["0xb", "0xd"], ["0xd", "0xa"]] - route = _get_shortest_route(start_swap, [end_swap], other_swaps) - assert len(route) == 3 + expected_shortest_route = [("0xa", "0xb"), ("0xb", "0xd"), ("0xd", "0xa")] + actual_shortest_route = _get_shortest_route(start_swap, [end_swap], other_swaps) + + assert actual_shortest_route is not None + _assert_route_tokens_equal(actual_shortest_route, expected_shortest_route) + + +def _assert_route_tokens_equal( + route: List[Swap], + expected_token_in_out_pairs: List[Tuple[str, str]], +) -> None: + assert len(route) == len(expected_token_in_out_pairs) for i, [expected_token_in, expected_token_out] in enumerate( - expected_smallest_route + expected_token_in_out_pairs ): assert expected_token_in == route[i].token_in_address assert expected_token_out == route[i].token_out_address From fa5be12e8113ed80b74d69bb993ae52affcef0f4 Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Wed, 22 Dec 2021 18:35:43 -0500 Subject: [PATCH 7/9] Fix docstring --- mev_inspect/arbitrages.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mev_inspect/arbitrages.py b/mev_inspect/arbitrages.py index b912d27..8852079 100644 --- a/mev_inspect/arbitrages.py +++ b/mev_inspect/arbitrages.py @@ -132,7 +132,7 @@ def _get_shortest_route( def _get_all_start_end_swaps(swaps: List[Swap]) -> List[Tuple[Swap, List[Swap]]]: """ - Gets the set of all possible opening and closing swap pairs in an arbitrage via + Gets the set of all possible openings and corresponding closing swaps for an arbitrage via - swap[start].token_in == swap[end].token_out - swap[start].from_address == swap[end].to_address - not swap[start].from_address in all_pool_addresses From bd99188f6eb0b29df799a52fcc280ec74cf66cdb Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Wed, 22 Dec 2021 18:36:26 -0500 Subject: [PATCH 8/9] Rename rest --- mev_inspect/arbitrages.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mev_inspect/arbitrages.py b/mev_inspect/arbitrages.py index 8852079..893c159 100644 --- a/mev_inspect/arbitrages.py +++ b/mev_inspect/arbitrages.py @@ -104,7 +104,7 @@ def _get_shortest_route( if len(other_swaps) == 0: return None - shortest_route_rest = None + shortest_remaining_route = None for next_swap in other_swaps: if start_swap.token_out_address == next_swap.token_in_address and ( @@ -119,15 +119,15 @@ def _get_shortest_route( ) if shortest_from_next is not None and ( - shortest_route_rest is None - or len(shortest_from_next) < len(shortest_route_rest) + shortest_remaining_route is None + or len(shortest_from_next) < len(shortest_remaining_route) ): - shortest_route_rest = shortest_from_next + shortest_remaining_route = shortest_from_next - if shortest_route_rest is None: + if shortest_remaining_route is None: return None else: - return [start_swap] + shortest_route_rest + return [start_swap] + shortest_remaining_route def _get_all_start_end_swaps(swaps: List[Swap]) -> List[Tuple[Swap, List[Swap]]]: From b588e115ce0b6fcde72c0698ebbe3f55b348efe2 Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Wed, 22 Dec 2021 22:42:26 -0500 Subject: [PATCH 9/9] Fix reverting arbitrage tests --- tests/test_arbitrage_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_arbitrage_integration.py b/tests/test_arbitrage_integration.py index 8437a3c..9dd8b3a 100644 --- a/tests/test_arbitrage_integration.py +++ b/tests/test_arbitrage_integration.py @@ -67,7 +67,7 @@ def test_reverting_arbitrage(trace_classifier: TraceClassifier): assert len(swaps) == 38 arbitrages = get_arbitrages(list(swaps)) - assert len(arbitrages) == 21 + assert len(arbitrages) == 4 arbitrage_1 = [ arb