diff --git a/alembic/versions/0cef835f7b36_rename_pool_address_to_contract_address.py b/alembic/versions/0cef835f7b36_rename_pool_address_to_contract_address.py new file mode 100644 index 0000000..c519828 --- /dev/null +++ b/alembic/versions/0cef835f7b36_rename_pool_address_to_contract_address.py @@ -0,0 +1,27 @@ +"""Rename pool_address to contract_address + +Revision ID: 0cef835f7b36 +Revises: 5427d62a2cc0 +Create Date: 2021-11-19 15:36:15.152622 + +""" +from alembic import op + + +# revision identifiers, used by Alembic. +revision = "0cef835f7b36" +down_revision = "5427d62a2cc0" +branch_labels = None +depends_on = None + + +def upgrade(): + op.alter_column( + "swaps", "pool_address", nullable=False, new_column_name="contract_address" + ) + + +def downgrade(): + op.alter_column( + "swaps", "contract_address", nullable=False, new_column_name="pool_address" + ) diff --git a/mev_inspect/arbitrages.py b/mev_inspect/arbitrages.py index 40529d7..c13c8fe 100644 --- a/mev_inspect/arbitrages.py +++ b/mev_inspect/arbitrages.py @@ -86,7 +86,7 @@ def _get_all_start_end_swaps(swaps: List[Swap]) -> List[Tuple[Swap, Swap]]: - not swap[start].from_address in all_pool_addresses - not swap[end].to_address in all_pool_addresses """ - pool_addrs = [swap.pool_address for swap in swaps] + pool_addrs = [swap.contract_address for swap in swaps] valid_start_ends: List[Tuple[Swap, Swap]] = [] for potential_start_swap in swaps: for potential_end_swap in swaps: @@ -116,8 +116,8 @@ def _get_all_routes( 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.pool_address == potential_next_swap.from_address - or start_swap.to_address == potential_next_swap.pool_address + 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 = [ diff --git a/mev_inspect/classifiers/swaps.py b/mev_inspect/classifiers/swaps.py index 601eca7..58d6440 100644 --- a/mev_inspect/classifiers/swaps.py +++ b/mev_inspect/classifiers/swaps.py @@ -43,7 +43,7 @@ def create_swap_from_transfers( transaction_hash=trace.transaction_hash, block_number=trace.block_number, trace_address=trace.trace_address, - pool_address=pool_address, + contract_address=pool_address, protocol=trace.protocol, from_address=transfer_in.from_address, to_address=transfer_out.to_address, diff --git a/mev_inspect/schemas/swaps.py b/mev_inspect/schemas/swaps.py index b702cf6..477898a 100644 --- a/mev_inspect/schemas/swaps.py +++ b/mev_inspect/schemas/swaps.py @@ -10,7 +10,7 @@ class Swap(BaseModel): transaction_hash: str block_number: int trace_address: List[int] - pool_address: str + contract_address: str from_address: str to_address: str token_in_address: str diff --git a/tests/helpers.py b/tests/helpers.py index d28e990..bae7b30 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -44,7 +44,7 @@ def make_swap_trace( transaction_hash: str, trace_address: List[int], from_address: str, - pool_address: str, + contract_address: str, abi_name: str, function_signature: str, protocol: Optional[Protocol], @@ -60,7 +60,7 @@ def make_swap_trace( subtraces=0, classification=Classification.swap, from_address=from_address, - to_address=pool_address, + to_address=contract_address, function_name="swap", function_signature=function_signature, inputs={recipient_input_key: recipient_address}, diff --git a/tests/test_arbitrages.py b/tests/test_arbitrages.py index 5ac6d52..fb07e9d 100644 --- a/tests/test_arbitrages.py +++ b/tests/test_arbitrages.py @@ -32,7 +32,7 @@ def test_two_pool_arbitrage(get_transaction_hashes, get_addresses): transaction_hash=transaction_hash, block_number=block_number, trace_address=[0], - pool_address=first_pool_address, + contract_address=first_pool_address, from_address=account_address, to_address=second_pool_address, token_in_address=first_token_address, @@ -45,7 +45,7 @@ def test_two_pool_arbitrage(get_transaction_hashes, get_addresses): transaction_hash=transaction_hash, block_number=block_number, trace_address=[1], - pool_address=second_pool_address, + contract_address=second_pool_address, from_address=first_pool_address, to_address=account_address, token_in_address=second_token_address, @@ -60,7 +60,7 @@ def test_two_pool_arbitrage(get_transaction_hashes, get_addresses): transaction_hash=transaction_hash, block_number=block_number, trace_address=[2, 0], - pool_address=unrelated_pool_address, + contract_address=unrelated_pool_address, from_address=account_address, to_address=account_address, token_in_address=second_token_address, @@ -113,7 +113,7 @@ def test_three_pool_arbitrage(get_transaction_hashes, get_addresses): transaction_hash=transaction_hash, block_number=block_number, trace_address=[0], - pool_address=first_pool_address, + contract_address=first_pool_address, from_address=account_address, to_address=second_pool_address, token_in_address=first_token_address, @@ -126,7 +126,7 @@ def test_three_pool_arbitrage(get_transaction_hashes, get_addresses): transaction_hash=transaction_hash, block_number=block_number, trace_address=[1], - pool_address=second_pool_address, + contract_address=second_pool_address, from_address=first_pool_address, to_address=third_pool_address, token_in_address=second_token_address, @@ -139,7 +139,7 @@ def test_three_pool_arbitrage(get_transaction_hashes, get_addresses): transaction_hash=transaction_hash, block_number=block_number, trace_address=[2], - pool_address=third_pool_address, + contract_address=third_pool_address, from_address=second_pool_address, to_address=account_address, token_in_address=third_token_address, @@ -220,7 +220,7 @@ def create_generic_swap( transaction_hash="0xfake", block_number=0, trace_address=trace_address, - pool_address="0xfake", + contract_address="0xfake", from_address="0xfake", to_address="0xfake", token_in_address=tok_a, diff --git a/tests/test_swaps.py b/tests/test_swaps.py index a4fdefa..68e9071 100644 --- a/tests/test_swaps.py +++ b/tests/test_swaps.py @@ -63,7 +63,7 @@ def test_swaps( first_transaction_hash, trace_address=[1], from_address=alice_address, - pool_address=first_pool_address, + contract_address=first_pool_address, abi_name=UNISWAP_V2_PAIR_ABI_NAME, protocol=None, function_signature="swap(uint256,uint256,address,bytes)", @@ -84,7 +84,7 @@ def test_swaps( second_transaction_hash, trace_address=[], from_address=bob_address, - pool_address=second_pool_address, + contract_address=second_pool_address, abi_name=UNISWAP_V3_POOL_ABI_NAME, protocol=None, function_signature="swap(address,bool,int256,uint160,bytes)", @@ -132,7 +132,7 @@ def test_swaps( third_transaction_hash, trace_address=[6], from_address=bob_address, - pool_address=third_pool_address, + contract_address=third_pool_address, abi_name=BALANCER_V1_POOL_ABI_NAME, protocol=Protocol.balancer_v1, function_signature="swapExactAmountIn(address,uint256,address,uint256,uint256)", @@ -160,7 +160,7 @@ def test_swaps( assert uni_v2_swap.block_number == block_number assert uni_v2_swap.trace_address == [1] assert uni_v2_swap.protocol is None - assert uni_v2_swap.pool_address == first_pool_address + assert uni_v2_swap.contract_address == first_pool_address assert uni_v2_swap.from_address == alice_address assert uni_v2_swap.to_address == bob_address assert uni_v2_swap.token_in_address == first_token_in_address @@ -173,7 +173,7 @@ def test_swaps( assert uni_v3_swap.block_number == block_number assert uni_v3_swap.trace_address == [] assert uni_v3_swap.protocol is None - assert uni_v3_swap.pool_address == second_pool_address + assert uni_v3_swap.contract_address == second_pool_address assert uni_v3_swap.from_address == bob_address assert uni_v3_swap.to_address == carl_address assert uni_v3_swap.token_in_address == second_token_in_address @@ -186,7 +186,7 @@ def test_swaps( assert bal_v1_swap.block_number == block_number assert bal_v1_swap.trace_address == [6] assert bal_v1_swap.protocol == Protocol.balancer_v1 - assert bal_v1_swap.pool_address == third_pool_address + assert bal_v1_swap.contract_address == third_pool_address assert bal_v1_swap.from_address == bob_address assert bal_v1_swap.to_address == bob_address assert bal_v1_swap.token_in_address == third_token_in_address