Rename Transfer to ERC20Transfer
This commit is contained in:
parent
bf6d5d2861
commit
f35a727b36
@ -5,7 +5,7 @@ from pydantic import BaseModel
|
||||
from .classified_traces import Classification, ClassifiedTrace, Protocol
|
||||
|
||||
|
||||
class Transfer(BaseModel):
|
||||
class ERC20Transfer(BaseModel):
|
||||
transaction_hash: str
|
||||
trace_address: List[int]
|
||||
from_address: str
|
||||
@ -14,7 +14,7 @@ class Transfer(BaseModel):
|
||||
token_address: str
|
||||
|
||||
@classmethod
|
||||
def from_trace(cls, trace: ClassifiedTrace) -> "Transfer":
|
||||
def from_trace(cls, trace: ClassifiedTrace) -> "ERC20Transfer":
|
||||
if trace.classification != Classification.transfer or trace.inputs is None:
|
||||
raise ValueError("Invalid transfer")
|
||||
|
||||
|
@ -6,7 +6,7 @@ from mev_inspect.schemas.classified_traces import (
|
||||
Classification,
|
||||
)
|
||||
from mev_inspect.schemas.swaps import Swap
|
||||
from mev_inspect.schemas.transfers import Transfer
|
||||
from mev_inspect.schemas.transfers import ERC20Transfer
|
||||
from mev_inspect.transfers import (
|
||||
get_child_transfers,
|
||||
filter_transfers,
|
||||
@ -37,11 +37,11 @@ def _get_swaps_for_transaction(traces: List[ClassifiedTrace]) -> List[Swap]:
|
||||
ordered_traces = list(sorted(traces, key=lambda t: t.trace_address))
|
||||
|
||||
swaps: List[Swap] = []
|
||||
prior_transfers: List[Transfer] = []
|
||||
prior_transfers: List[ERC20Transfer] = []
|
||||
|
||||
for trace in ordered_traces:
|
||||
if trace.classification == Classification.transfer:
|
||||
prior_transfers.append(Transfer.from_trace(trace))
|
||||
prior_transfers.append(ERC20Transfer.from_trace(trace))
|
||||
|
||||
elif trace.classification == Classification.swap:
|
||||
child_transfers = get_child_transfers(
|
||||
@ -64,8 +64,8 @@ def _get_swaps_for_transaction(traces: List[ClassifiedTrace]) -> List[Swap]:
|
||||
|
||||
def _parse_swap(
|
||||
trace: ClassifiedTrace,
|
||||
prior_transfers: List[Transfer],
|
||||
child_transfers: List[Transfer],
|
||||
prior_transfers: List[ERC20Transfer],
|
||||
child_transfers: List[ERC20Transfer],
|
||||
) -> Optional[Swap]:
|
||||
pool_address = trace.to_address
|
||||
recipient_address = _get_recipient_address(trace)
|
||||
|
@ -1,7 +1,7 @@
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from mev_inspect.schemas.classified_traces import Classification, ClassifiedTrace
|
||||
from mev_inspect.schemas.transfers import Transfer
|
||||
from mev_inspect.schemas.transfers import ERC20Transfer
|
||||
from mev_inspect.traces import is_child_trace_address, get_child_traces
|
||||
|
||||
|
||||
@ -9,21 +9,21 @@ def get_child_transfers(
|
||||
transaction_hash: str,
|
||||
parent_trace_address: List[int],
|
||||
traces: List[ClassifiedTrace],
|
||||
) -> List[Transfer]:
|
||||
) -> List[ERC20Transfer]:
|
||||
child_transfers = []
|
||||
|
||||
for child_trace in get_child_traces(transaction_hash, parent_trace_address, traces):
|
||||
if child_trace.classification == Classification.transfer:
|
||||
child_transfers.append(Transfer.from_trace(child_trace))
|
||||
child_transfers.append(ERC20Transfer.from_trace(child_trace))
|
||||
|
||||
return child_transfers
|
||||
|
||||
|
||||
def filter_transfers(
|
||||
transfers: List[Transfer],
|
||||
transfers: List[ERC20Transfer],
|
||||
to_address: Optional[str] = None,
|
||||
from_address: Optional[str] = None,
|
||||
) -> List[Transfer]:
|
||||
) -> List[ERC20Transfer]:
|
||||
filtered_transfers = []
|
||||
|
||||
for transfer in transfers:
|
||||
@ -38,7 +38,9 @@ def filter_transfers(
|
||||
return filtered_transfers
|
||||
|
||||
|
||||
def remove_child_transfers_of_transfers(transfers: List[Transfer]) -> List[Transfer]:
|
||||
def remove_child_transfers_of_transfers(
|
||||
transfers: List[ERC20Transfer],
|
||||
) -> List[ERC20Transfer]:
|
||||
updated_transfers = []
|
||||
transfer_addresses_by_transaction: Dict[str, List[List[int]]] = {}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
from mev_inspect.schemas.transfers import Transfer
|
||||
from mev_inspect.schemas.transfers import ERC20Transfer
|
||||
from mev_inspect.transfers import remove_child_transfers_of_transfers
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ def test_remove_child_transfers_of_transfers(get_transaction_hashes, get_address
|
||||
third_token_address,
|
||||
] = get_addresses(5)
|
||||
|
||||
outer_transfer = Transfer(
|
||||
outer_transfer = ERC20Transfer(
|
||||
transaction_hash=transaction_hash,
|
||||
trace_address=[0],
|
||||
from_address=alice_address,
|
||||
@ -22,7 +22,7 @@ def test_remove_child_transfers_of_transfers(get_transaction_hashes, get_address
|
||||
token_address=first_token_address,
|
||||
)
|
||||
|
||||
inner_transfer = Transfer(
|
||||
inner_transfer = ERC20Transfer(
|
||||
**{
|
||||
**outer_transfer.dict(),
|
||||
**dict(
|
||||
@ -32,7 +32,7 @@ def test_remove_child_transfers_of_transfers(get_transaction_hashes, get_address
|
||||
}
|
||||
)
|
||||
|
||||
other_transfer = Transfer(
|
||||
other_transfer = ERC20Transfer(
|
||||
transaction_hash=transaction_hash,
|
||||
trace_address=[1],
|
||||
from_address=bob_address,
|
||||
@ -41,7 +41,7 @@ def test_remove_child_transfers_of_transfers(get_transaction_hashes, get_address
|
||||
token_address=third_token_address,
|
||||
)
|
||||
|
||||
separate_transaction_transfer = Transfer(
|
||||
separate_transaction_transfer = ERC20Transfer(
|
||||
**{
|
||||
**inner_transfer.dict(),
|
||||
**dict(transaction_hash=other_transaction_hash),
|
||||
|
Loading…
x
Reference in New Issue
Block a user