From c334441e95c78855bfa14ef60475f2a169ab2e6e Mon Sep 17 00:00:00 2001 From: Gui Heise Date: Tue, 23 Nov 2021 11:28:15 -0500 Subject: [PATCH] Add assertion and move constants up --- mev_inspect/classifiers/helpers.py | 7 ++++--- tests/test_0x.py | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mev_inspect/classifiers/helpers.py b/mev_inspect/classifiers/helpers.py index 9ce4c7f..84d1f8b 100644 --- a/mev_inspect/classifiers/helpers.py +++ b/mev_inspect/classifiers/helpers.py @@ -5,6 +5,7 @@ from mev_inspect.schemas.transfers import Transfer, ETH_TOKEN_ADDRESS from mev_inspect.schemas.traces import DecodedCallTrace, ClassifiedTrace +ANY_TAKER_ADDRESS = "0x0000000000000000000000000000000000000000" RFQ_SIGNATURES = [ "fillRfqOrder((address,address,uint128,uint128,address,address,address,bytes32,uint64,uint256),(uint8,uint8,bytes32,bytes32),uint128)", @@ -114,6 +115,8 @@ def is_valid_0x_swap( f"0x orderbook function {trace.function_signature} is not supported" ) + # 3. The swap should not be a child of previous swaps in the block + return True @@ -121,9 +124,7 @@ def _get_taker_token_in_amount( taker_address: str, token_in_address: str, child_transfers: List[Transfer] ) -> int: - ANY_TAKER = "0x0000000000000000000000000000000000000000" - - if taker_address == ANY_TAKER: + if taker_address == ANY_TAKER_ADDRESS: for transfer in child_transfers: if transfer.token_address == token_in_address: return transfer.amount diff --git a/tests/test_0x.py b/tests/test_0x.py index 90fc79b..1b62086 100644 --- a/tests/test_0x.py +++ b/tests/test_0x.py @@ -34,6 +34,7 @@ def test_fillLimitOrder_swap(): result = get_swaps(classified_traces) assert swap in result + assert result.count(swap) == 1 def test__fillLimitOrder_swap(): @@ -65,6 +66,7 @@ def test__fillLimitOrder_swap(): result = get_swaps(classified_traces) assert swap in result + assert result.count(swap) == 1 def test_RfqLimitOrder_swap(): @@ -96,6 +98,7 @@ def test_RfqLimitOrder_swap(): result = get_swaps(classified_traces) assert swap in result + assert result.count(swap) == 1 def test__RfqLimitOrder_swap(): @@ -127,3 +130,4 @@ def test__RfqLimitOrder_swap(): result = get_swaps(classified_traces) assert swap in result + assert result.count(swap) == 1