Remove unused imports, improve variable names
This commit is contained in:
parent
91428d491c
commit
82a6c72f6a
@ -1,33 +1,32 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from mev_inspect.schemas.classified_traces import (
|
from mev_inspect.schemas.classified_traces import (
|
||||||
Classification,
|
|
||||||
ClassifiedTrace,
|
ClassifiedTrace,
|
||||||
# CallTrace,
|
|
||||||
DecodedCallTrace,
|
DecodedCallTrace,
|
||||||
|
Classification,
|
||||||
)
|
)
|
||||||
from mev_inspect.schemas.liquidations import Liquidation
|
from mev_inspect.schemas.liquidations import Liquidation
|
||||||
|
|
||||||
|
contract_addresses = [
|
||||||
|
"0x3dfd23A6c5E8BbcFc9581d2E864a68feb6a076d3",
|
||||||
|
"0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9",
|
||||||
|
"0x398eC7346DcD622eDc5ae82352F02bE94C62d119",
|
||||||
|
]
|
||||||
|
|
||||||
# Inspect list of classified traces and identify liquidation
|
|
||||||
def get_liquidations(traces: List[ClassifiedTrace]):
|
def get_liquidations(traces: List[ClassifiedTrace]) -> List[Liquidation]:
|
||||||
|
"""Inspect list of classified traces and identify liquidation"""
|
||||||
tx = []
|
tx = []
|
||||||
liquidations = []
|
liquidations = []
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
# Protocol contract address must be in included, below is AaveLendingPoolCoreV1
|
# Protocol contract address must be in included
|
||||||
addrs = [
|
|
||||||
"0x3dfd23A6c5E8BbcFc9581d2E864a68feb6a076d3",
|
|
||||||
"0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9",
|
|
||||||
"0x398eC7346DcD622eDc5ae82352F02bE94C62d119",
|
|
||||||
]
|
|
||||||
|
|
||||||
# Used to remove double-counted 'from' transfers
|
# Used to remove double-counted 'from' transfers
|
||||||
from_doubles = []
|
unique_transfers = []
|
||||||
transfers_to = []
|
transfers_to = []
|
||||||
transfers_from = []
|
transfers_from = []
|
||||||
|
|
||||||
# For each trace
|
|
||||||
for trace in traces:
|
for trace in traces:
|
||||||
|
|
||||||
if isinstance(trace, DecodedCallTrace):
|
if isinstance(trace, DecodedCallTrace):
|
||||||
@ -39,7 +38,7 @@ def get_liquidations(traces: List[ClassifiedTrace]):
|
|||||||
):
|
):
|
||||||
|
|
||||||
liquidations.append(trace)
|
liquidations.append(trace)
|
||||||
addrs.append(trace.from_address)
|
contract_addresses.append(trace.from_address)
|
||||||
tx.append(trace.transaction_hash)
|
tx.append(trace.transaction_hash)
|
||||||
|
|
||||||
# Found liquidation, now parse inputs for data
|
# Found liquidation, now parse inputs for data
|
||||||
@ -54,11 +53,11 @@ def get_liquidations(traces: List[ClassifiedTrace]):
|
|||||||
reserve = trace.inputs[input]
|
reserve = trace.inputs[input]
|
||||||
# This will be the address of the received token
|
# This will be the address of the received token
|
||||||
elif input == "_user":
|
elif input == "_user":
|
||||||
liquidated_usr = trace.inputs[input]
|
liquidated_user = trace.inputs[input]
|
||||||
# Register liquidation
|
# Register liquidation
|
||||||
result.append(
|
result.append(
|
||||||
Liquidation(
|
Liquidation(
|
||||||
liquidated_usr=liquidated_usr,
|
liquidated_user=liquidated_user,
|
||||||
collateral_address=collateral_address,
|
collateral_address=collateral_address,
|
||||||
collateral_amount=liquidation_amount,
|
collateral_amount=liquidation_amount,
|
||||||
collateral_source="",
|
collateral_source="",
|
||||||
@ -70,31 +69,31 @@ def get_liquidations(traces: List[ClassifiedTrace]):
|
|||||||
elif (
|
elif (
|
||||||
trace.classification == Classification.transfer
|
trace.classification == Classification.transfer
|
||||||
and "sender" in trace.inputs
|
and "sender" in trace.inputs
|
||||||
and trace.inputs["sender"] in addrs
|
and trace.inputs["sender"] in contract_addresses
|
||||||
and trace.transaction_hash not in from_doubles
|
and trace.transaction_hash not in unique_transfers
|
||||||
):
|
):
|
||||||
|
|
||||||
# Add the transfer
|
# Add the transfer
|
||||||
liquidator = next(
|
liquidator = next(
|
||||||
addrs[i]
|
contract_addresses[i]
|
||||||
for i in range(len(addrs))
|
for i in range(len(contract_addresses))
|
||||||
if trace.inputs["sender"] == addrs[i]
|
if trace.inputs["sender"] == contract_addresses[i]
|
||||||
)
|
)
|
||||||
transfers_from.append(
|
transfers_from.append(
|
||||||
["from", liquidator, trace.transaction_hash, trace.inputs["amount"]]
|
["from", liquidator, trace.transaction_hash, trace.inputs["amount"]]
|
||||||
)
|
)
|
||||||
from_doubles.append(trace.transaction_hash)
|
unique_transfers.append(trace.transaction_hash)
|
||||||
|
|
||||||
# Check for transfer to a liquidator
|
# Check for transfer to a liquidator
|
||||||
elif (
|
elif (
|
||||||
trace.classification == Classification.transfer
|
trace.classification == Classification.transfer
|
||||||
and trace.inputs["recipient"] in addrs
|
and trace.inputs["recipient"] in contract_addresses
|
||||||
):
|
):
|
||||||
# Add the transfer
|
# Add the transfer
|
||||||
liquidator = next(
|
liquidator = next(
|
||||||
addrs[i]
|
contract_addresses[i]
|
||||||
for i in range(len(addrs))
|
for i in range(len(contract_addresses))
|
||||||
if trace.inputs["recipient"] == addrs[i]
|
if trace.inputs["recipient"] == contract_addresses[i]
|
||||||
)
|
)
|
||||||
transfers_to.append(
|
transfers_to.append(
|
||||||
["to", liquidator, trace.transaction_hash, trace.inputs["amount"]]
|
["to", liquidator, trace.transaction_hash, trace.inputs["amount"]]
|
||||||
|
@ -4,7 +4,7 @@ from .classified_traces import ClassifiedTrace
|
|||||||
|
|
||||||
|
|
||||||
class Liquidation(BaseModel):
|
class Liquidation(BaseModel):
|
||||||
liquidated_usr: str
|
liquidated_user: str
|
||||||
collateral_address: str
|
collateral_address: str
|
||||||
collateral_amount: int
|
collateral_amount: int
|
||||||
collateral_source: str
|
collateral_source: str
|
||||||
|
Loading…
x
Reference in New Issue
Block a user