Remove try, update transfer_to keys, add child trace parsing and removal
This commit is contained in:
parent
8b5d1327a8
commit
b215a1d9b2
@ -1,6 +1,6 @@
|
|||||||
from typing import List, Optional, Dict
|
from typing import List, Optional, Dict
|
||||||
|
|
||||||
|
from mev_inspect.traces import get_child_traces
|
||||||
from mev_inspect.schemas.classified_traces import (
|
from mev_inspect.schemas.classified_traces import (
|
||||||
ClassifiedTrace,
|
ClassifiedTrace,
|
||||||
DecodedCallTrace,
|
DecodedCallTrace,
|
||||||
@ -54,35 +54,37 @@ def get_liquidations(
|
|||||||
"""Inspect list of classified traces and identify liquidation"""
|
"""Inspect list of classified traces and identify liquidation"""
|
||||||
liquidations: List[Liquidation] = []
|
liquidations: List[Liquidation] = []
|
||||||
transfers_to: Dict = {}
|
transfers_to: Dict = {}
|
||||||
unique_transaction_hashes: List = []
|
|
||||||
|
|
||||||
for trace in traces:
|
for trace in traces:
|
||||||
|
|
||||||
if (
|
if trace.classification == Classification.liquidate and isinstance(
|
||||||
trace.classification == Classification.liquidate
|
trace, DecodedCallTrace
|
||||||
and isinstance(trace, DecodedCallTrace)
|
|
||||||
and trace.transaction_hash not in unique_transaction_hashes
|
|
||||||
):
|
):
|
||||||
|
|
||||||
liquidator = trace.from_address
|
liquidator = trace.from_address
|
||||||
unique_transaction_hashes.append(trace.transaction_hash)
|
|
||||||
|
|
||||||
for t in traces:
|
child_traces = get_child_traces(
|
||||||
to_result = find_transfer_to_liquidator(t, liquidator)
|
trace.transaction_hash, trace.trace_address, traces
|
||||||
|
)
|
||||||
|
|
||||||
|
for child in child_traces:
|
||||||
|
|
||||||
|
if child.classification == Classification.liquidate:
|
||||||
|
traces.remove(child)
|
||||||
|
|
||||||
|
to_result = find_transfer_to_liquidator(child, liquidator)
|
||||||
if to_result and not (
|
if to_result and not (
|
||||||
to_result.transaction_hash in transfers_to.keys()
|
to_result.transaction_hash in transfers_to.keys()
|
||||||
):
|
):
|
||||||
transfers_to[trace.transaction_hash] = to_result
|
transfers_to[str(trace.to_address)] = to_result
|
||||||
|
|
||||||
if "amount" in transfers_to[trace.transaction_hash].inputs:
|
if "amount" in transfers_to[str(trace.to_address)].inputs:
|
||||||
received_amount = int(
|
received_amount = int(
|
||||||
transfers_to[trace.transaction_hash].inputs["amount"]
|
transfers_to[str(trace.to_address)].inputs["amount"]
|
||||||
)
|
)
|
||||||
|
|
||||||
elif "wad" in transfers_to[trace.transaction_hash].inputs:
|
elif "wad" in transfers_to[str(trace.to_address)].inputs:
|
||||||
received_amount = int(
|
received_amount = int(transfers_to[str(trace.to_address)].inputs["wad"])
|
||||||
transfers_to[trace.transaction_hash].inputs["wad"]
|
|
||||||
)
|
|
||||||
|
|
||||||
liquidations.append(
|
liquidations.append(
|
||||||
Liquidation(
|
Liquidation(
|
||||||
@ -99,6 +101,7 @@ def get_liquidations(
|
|||||||
block_number=trace.block_number,
|
block_number=trace.block_number,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
print("\n")
|
print("\n")
|
||||||
print(liquidations)
|
print(liquidations)
|
||||||
return liquidations
|
return liquidations
|
||||||
|
@ -5,12 +5,8 @@ from mev_inspect.schemas.classified_traces import Protocol
|
|||||||
class Liquidation(BaseModel):
|
class Liquidation(BaseModel):
|
||||||
liquidated_user: str
|
liquidated_user: str
|
||||||
liquidator_user: str
|
liquidator_user: str
|
||||||
# collateral
|
|
||||||
collateral_token_address: str
|
collateral_token_address: str
|
||||||
# collateral_amount: int
|
|
||||||
# debtToCover
|
|
||||||
debt_token_address: str
|
debt_token_address: str
|
||||||
# purchaseAmount
|
|
||||||
debt_purchase_amount: int
|
debt_purchase_amount: int
|
||||||
received_token_address: str
|
received_token_address: str
|
||||||
received_amount: int
|
received_amount: int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user