Transfer function cleanup
This commit is contained in:
parent
02959e68da
commit
faa8d09312
@ -1,4 +1,4 @@
|
|||||||
from typing import List
|
from typing import List, Union
|
||||||
|
|
||||||
|
|
||||||
from mev_inspect.schemas.classified_traces import (
|
from mev_inspect.schemas.classified_traces import (
|
||||||
@ -14,18 +14,18 @@ from mev_inspect.schemas.transfers import Transfer, EthTransfer, ERC20Transfer
|
|||||||
liquidators: List[str] = []
|
liquidators: List[str] = []
|
||||||
|
|
||||||
|
|
||||||
def is_transfer_from_liquidator(trace: ClassifiedTrace, liquidator: str) -> bool:
|
def is_transfer_from_liquidator(
|
||||||
|
trace: ClassifiedTrace, liquidator: str
|
||||||
|
) -> Union[Transfer, ClassifiedTrace]:
|
||||||
"""Check if transfer is from liquidator"""
|
"""Check if transfer is from liquidator"""
|
||||||
|
transfer: Union[Transfer, ClassifiedTrace]
|
||||||
transfer: Transfer
|
result: Union[Transfer, ClassifiedTrace]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
transfer = ERC20Transfer.from_trace(trace)
|
transfer = ERC20Transfer.from_trace(trace)
|
||||||
if transfer.from_address == liquidator:
|
if transfer.from_address == liquidator:
|
||||||
return True
|
result = transfer
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
||||||
@ -35,31 +35,28 @@ def is_transfer_from_liquidator(trace: ClassifiedTrace, liquidator: str) -> bool
|
|||||||
|
|
||||||
transfer = EthTransfer.from_trace(trace)
|
transfer = EthTransfer.from_trace(trace)
|
||||||
if transfer.from_address == liquidator:
|
if transfer.from_address == liquidator:
|
||||||
return True
|
result = transfer
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
||||||
if trace.from_address == liquidator:
|
if trace.from_address == liquidator:
|
||||||
# print(trace.inputs)
|
result = trace
|
||||||
return True
|
|
||||||
else:
|
return result
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def is_transfer_to_liquidator(trace: ClassifiedTrace, liquidator: str) -> bool:
|
def is_transfer_to_liquidator(
|
||||||
|
trace: ClassifiedTrace, liquidator: str
|
||||||
|
) -> Union[Transfer, ClassifiedTrace]:
|
||||||
"""Check if transfer is to liquidator"""
|
"""Check if transfer is to liquidator"""
|
||||||
|
|
||||||
transfer: Transfer
|
transfer: Union[Transfer, ClassifiedTrace]
|
||||||
|
result: Union[Transfer, ClassifiedTrace]
|
||||||
try:
|
try:
|
||||||
|
|
||||||
transfer = ERC20Transfer.from_trace(trace)
|
transfer = ERC20Transfer.from_trace(trace)
|
||||||
if transfer.to_address == liquidator:
|
if transfer.to_address == liquidator:
|
||||||
return True
|
result = transfer
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
||||||
@ -69,18 +66,14 @@ def is_transfer_to_liquidator(trace: ClassifiedTrace, liquidator: str) -> bool:
|
|||||||
|
|
||||||
transfer = EthTransfer.from_trace(trace)
|
transfer = EthTransfer.from_trace(trace)
|
||||||
if transfer.to_address == liquidator:
|
if transfer.to_address == liquidator:
|
||||||
print(transfer.amount, transfer.from_address)
|
result = transfer
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
||||||
if trace.to_address == liquidator:
|
if trace.to_address == liquidator:
|
||||||
# print(trace.inputs)
|
result = trace
|
||||||
return True
|
|
||||||
else:
|
return result
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def get_liquidations(
|
def get_liquidations(
|
||||||
@ -104,18 +97,17 @@ def get_liquidations(
|
|||||||
|
|
||||||
liquidator = trace.from_address
|
liquidator = trace.from_address
|
||||||
|
|
||||||
transfers_to = [
|
for t in traces:
|
||||||
EthTransfer.from_trace(t)
|
|
||||||
for t in traces
|
|
||||||
if is_transfer_to_liquidator(t, liquidator)
|
|
||||||
]
|
|
||||||
print(transfers_to)
|
|
||||||
|
|
||||||
transfers_from = [
|
from_result = is_transfer_from_liquidator(t, liquidator)
|
||||||
EthTransfer.from_trace(t)
|
if from_result:
|
||||||
for t in traces
|
transfers_from.append(from_result)
|
||||||
if is_transfer_from_liquidator(t, liquidator)
|
|
||||||
]
|
to_result = is_transfer_to_liquidator(t, liquidator)
|
||||||
|
if to_result:
|
||||||
|
transfers_to.append(to_result)
|
||||||
|
|
||||||
|
print(transfers_to)
|
||||||
print(transfers_from)
|
print(transfers_from)
|
||||||
|
|
||||||
unique_transaction_hashes.append(trace.transaction_hash)
|
unique_transaction_hashes.append(trace.transaction_hash)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user