Redefine transfer functions and add liquidator
This commit is contained in:
parent
0a770511a4
commit
e7b3bb4ac7
@ -9,6 +9,35 @@ from mev_inspect.schemas.classified_traces import (
|
||||
)
|
||||
|
||||
from mev_inspect.schemas.liquidations import Liquidation
|
||||
from mev_inspect.schemas.transfers import EthTransfer
|
||||
|
||||
liquidators = []
|
||||
|
||||
|
||||
def is_transfer_from_liquidator(
|
||||
trace: ClassifiedTrace,
|
||||
) -> bool:
|
||||
"""Check if transfer is from liquidator"""
|
||||
transfer = EthTransfer.from_trace(trace)
|
||||
if (
|
||||
trace.classification == Classification.transfer
|
||||
and transfer.from_address in liquidators
|
||||
):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def is_transfer_to_liquidator(trace: ClassifiedTrace) -> bool:
|
||||
"""Check if transfer is to liquidator"""
|
||||
transfer = EthTransfer.from_trace(trace)
|
||||
if (
|
||||
trace.classification == Classification.transfer
|
||||
and transfer.to_address in liquidators
|
||||
):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def get_liquidations(
|
||||
@ -18,28 +47,50 @@ def get_liquidations(
|
||||
"""Inspect list of classified traces and identify liquidation"""
|
||||
# liquidation_traces: List[DecodedCallTrace] = []
|
||||
liquidations: List[Liquidation] = []
|
||||
transfers_to: List = []
|
||||
transfers_from: List = []
|
||||
unique_transaction_hashes: List = []
|
||||
|
||||
for trace in traces:
|
||||
|
||||
if trace.classification == Classification.liquidate and isinstance(
|
||||
trace, DecodedCallTrace
|
||||
if (
|
||||
trace.classification == Classification.liquidate
|
||||
and isinstance(trace, DecodedCallTrace)
|
||||
and trace.transaction_hash not in unique_transaction_hashes
|
||||
):
|
||||
|
||||
liquidators.append(trace.from_address)
|
||||
transfer = EthTransfer.from_trace(trace)
|
||||
unique_transaction_hashes.append(trace.transaction_hash)
|
||||
|
||||
liquidations.append(
|
||||
Liquidation(
|
||||
liquidated_user=trace.inputs["_user"],
|
||||
liquidator_user=trace.inputs["_liquidator"],
|
||||
collateral_token_address=trace.inputs["_collateral"],
|
||||
collateral_amount=trace.inputs["_liquidatedCollateralAmount"],
|
||||
debt_token_address=trace.inputs["_reserve"],
|
||||
liquidator_user=transfer.from_address,
|
||||
debt_purchase_amount=trace.inputs["_purchaseAmount"],
|
||||
# received_token_address=,
|
||||
# received_amount=,
|
||||
protocol=Protocol.aave,
|
||||
transaction_hash=trace.transaction_hash,
|
||||
block_number=trace.block_number,
|
||||
)
|
||||
)
|
||||
|
||||
elif is_transfer_from_liquidator(trace):
|
||||
|
||||
# Add the transfer
|
||||
print(trace)
|
||||
transfers_from.append(EthTransfer.from_trace(trace))
|
||||
unique_transaction_hashes.append(trace.transaction_hash)
|
||||
|
||||
elif is_transfer_to_liquidator(trace):
|
||||
|
||||
# Add the transfer
|
||||
print(trace)
|
||||
transfers_to.append(EthTransfer.from_trace(trace))
|
||||
|
||||
print(unique_transaction_hashes)
|
||||
print(transfers_to)
|
||||
print(transfers_from)
|
||||
print(liquidations)
|
||||
return liquidations
|
||||
|
@ -46,5 +46,19 @@ class ABIFunctionDescription(BaseModel):
|
||||
return f"{self.name}({joined_input_types})"
|
||||
|
||||
|
||||
class ABIEventDescription(BaseModel):
|
||||
type: Literal[ABIDescriptionType.event]
|
||||
name: str
|
||||
inputs: List[ABIDescriptionInput]
|
||||
|
||||
def get_selector(self) -> HexBytes:
|
||||
signature = self.get_signature()
|
||||
return Web3.sha3(text=signature)[0:4]
|
||||
|
||||
def get_signature(self) -> HexBytes:
|
||||
joined_input_types = ",".join(input.type for input in self.inputs)
|
||||
return f"{self.name}({joined_input_types})"
|
||||
|
||||
|
||||
ABIDescription = Union[ABIFunctionDescription, ABIGenericDescription]
|
||||
ABI = List[ABIDescription]
|
||||
|
@ -4,9 +4,9 @@ from mev_inspect.schemas.classified_traces import Protocol
|
||||
|
||||
class Liquidation(BaseModel):
|
||||
liquidated_user: str
|
||||
liquidator_user: str
|
||||
# liquidator_user: str
|
||||
collateral_token_address: str
|
||||
collateral_amount: int
|
||||
# collateral_amount: int
|
||||
debt_token_address: str
|
||||
debt_purchase_amount: int
|
||||
# received_token_address: str
|
||||
@ -14,3 +14,10 @@ class Liquidation(BaseModel):
|
||||
protocol: Protocol
|
||||
transaction_hash: str
|
||||
block_number: str
|
||||
|
||||
|
||||
class LiquidationData(Liquidation):
|
||||
liquidator_user: str
|
||||
collateral_amount: int
|
||||
received_token_address: str
|
||||
received_amount: int
|
||||
|
Loading…
x
Reference in New Issue
Block a user