Add received amount calculations and update functions
This commit is contained in:
parent
faa8d09312
commit
8385bb676b
@ -1,4 +1,4 @@
|
|||||||
from typing import List, Union
|
from typing import List, Optional, Dict
|
||||||
|
|
||||||
|
|
||||||
from mev_inspect.schemas.classified_traces import (
|
from mev_inspect.schemas.classified_traces import (
|
||||||
@ -9,71 +9,44 @@ from mev_inspect.schemas.classified_traces import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from mev_inspect.schemas.liquidations import Liquidation
|
from mev_inspect.schemas.liquidations import Liquidation
|
||||||
from mev_inspect.schemas.transfers import Transfer, EthTransfer, ERC20Transfer
|
|
||||||
|
|
||||||
liquidators: List[str] = []
|
AAVE_CONTRACT_ADDRESSES: List[str] = [
|
||||||
|
# AAVE Proxy
|
||||||
|
"0x398ec7346dcd622edc5ae82352f02be94c62d119",
|
||||||
def is_transfer_from_liquidator(
|
# AAVE V2
|
||||||
trace: ClassifiedTrace, liquidator: str
|
"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",
|
||||||
) -> Union[Transfer, ClassifiedTrace]:
|
# AAVE V1
|
||||||
"""Check if transfer is from liquidator"""
|
"0x3dfd23a6c5e8bbcfc9581d2e864a68feb6a076d3",
|
||||||
transfer: Union[Transfer, ClassifiedTrace]
|
# AAVE V2 WETH
|
||||||
result: Union[Transfer, ClassifiedTrace]
|
"0x030ba81f1c18d280636f32af80b9aad02cf0854e",
|
||||||
|
]
|
||||||
try:
|
|
||||||
|
|
||||||
transfer = ERC20Transfer.from_trace(trace)
|
|
||||||
if transfer.from_address == liquidator:
|
|
||||||
result = transfer
|
|
||||||
|
|
||||||
except ValueError:
|
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
|
|
||||||
transfer = EthTransfer.from_trace(trace)
|
|
||||||
if transfer.from_address == liquidator:
|
|
||||||
result = transfer
|
|
||||||
|
|
||||||
except ValueError:
|
|
||||||
|
|
||||||
if trace.from_address == liquidator:
|
|
||||||
result = trace
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def is_transfer_to_liquidator(
|
def is_transfer_to_liquidator(
|
||||||
trace: ClassifiedTrace, liquidator: str
|
trace: ClassifiedTrace, liquidator: str
|
||||||
) -> Union[Transfer, ClassifiedTrace]:
|
) -> Optional[ClassifiedTrace]:
|
||||||
"""Check if transfer is to liquidator"""
|
"""Check if transfer is to liquidator"""
|
||||||
|
|
||||||
transfer: Union[Transfer, ClassifiedTrace]
|
if isinstance(trace, DecodedCallTrace):
|
||||||
result: Union[Transfer, ClassifiedTrace]
|
|
||||||
try:
|
try:
|
||||||
|
if (
|
||||||
|
trace.inputs["recipient"] == liquidator
|
||||||
|
and trace.from_address in AAVE_CONTRACT_ADDRESSES
|
||||||
|
):
|
||||||
|
return trace
|
||||||
|
|
||||||
transfer = ERC20Transfer.from_trace(trace)
|
except KeyError:
|
||||||
if transfer.to_address == liquidator:
|
|
||||||
result = transfer
|
|
||||||
|
|
||||||
except ValueError:
|
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if (
|
||||||
|
trace.inputs["dst"] == liquidator
|
||||||
|
and trace.from_address in AAVE_CONTRACT_ADDRESSES
|
||||||
|
):
|
||||||
|
return trace
|
||||||
|
except KeyError:
|
||||||
|
return None
|
||||||
|
|
||||||
transfer = EthTransfer.from_trace(trace)
|
return None
|
||||||
if transfer.to_address == liquidator:
|
|
||||||
result = transfer
|
|
||||||
|
|
||||||
except ValueError:
|
|
||||||
|
|
||||||
if trace.to_address == liquidator:
|
|
||||||
result = trace
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def get_liquidations(
|
def get_liquidations(
|
||||||
@ -83,8 +56,7 @@ def get_liquidations(
|
|||||||
"""Inspect list of classified traces and identify liquidation"""
|
"""Inspect list of classified traces and identify liquidation"""
|
||||||
# liquidation_traces: List[DecodedCallTrace] = []
|
# liquidation_traces: List[DecodedCallTrace] = []
|
||||||
liquidations: List[Liquidation] = []
|
liquidations: List[Liquidation] = []
|
||||||
transfers_to: List = []
|
transfers_to: Dict = {}
|
||||||
transfers_from: List = []
|
|
||||||
unique_transaction_hashes: List = []
|
unique_transaction_hashes: List = []
|
||||||
|
|
||||||
for trace in traces:
|
for trace in traces:
|
||||||
@ -99,18 +71,21 @@ def get_liquidations(
|
|||||||
|
|
||||||
for t in traces:
|
for t in traces:
|
||||||
|
|
||||||
from_result = is_transfer_from_liquidator(t, liquidator)
|
|
||||||
if from_result:
|
|
||||||
transfers_from.append(from_result)
|
|
||||||
|
|
||||||
to_result = is_transfer_to_liquidator(t, liquidator)
|
to_result = is_transfer_to_liquidator(t, liquidator)
|
||||||
if to_result:
|
if to_result and not (
|
||||||
transfers_to.append(to_result)
|
to_result.transaction_hash in transfers_to.keys()
|
||||||
|
):
|
||||||
print(transfers_to)
|
transfers_to[trace.transaction_hash] = to_result
|
||||||
print(transfers_from)
|
|
||||||
|
|
||||||
unique_transaction_hashes.append(trace.transaction_hash)
|
unique_transaction_hashes.append(trace.transaction_hash)
|
||||||
|
try:
|
||||||
|
received_amount = int(
|
||||||
|
transfers_to[trace.transaction_hash].inputs["amount"]
|
||||||
|
)
|
||||||
|
except KeyError:
|
||||||
|
received_amount = int(
|
||||||
|
transfers_to[trace.transaction_hash].inputs["wad"]
|
||||||
|
)
|
||||||
|
|
||||||
liquidations.append(
|
liquidations.append(
|
||||||
Liquidation(
|
Liquidation(
|
||||||
@ -120,6 +95,7 @@ def get_liquidations(
|
|||||||
liquidator_user=liquidator,
|
liquidator_user=liquidator,
|
||||||
debt_purchase_amount=trace.inputs["_purchaseAmount"],
|
debt_purchase_amount=trace.inputs["_purchaseAmount"],
|
||||||
protocol=Protocol.aave,
|
protocol=Protocol.aave,
|
||||||
|
received_amount=received_amount,
|
||||||
# aToken lookup is out of scope for now, WIP
|
# aToken lookup is out of scope for now, WIP
|
||||||
received_token_address=trace.inputs["_collateral"],
|
received_token_address=trace.inputs["_collateral"],
|
||||||
transaction_hash=trace.transaction_hash,
|
transaction_hash=trace.transaction_hash,
|
||||||
@ -127,5 +103,8 @@ def get_liquidations(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
print("\n")
|
||||||
|
print(transfers_to)
|
||||||
|
print("\n")
|
||||||
print(liquidations)
|
print(liquidations)
|
||||||
return liquidations
|
return liquidations
|
||||||
|
@ -13,7 +13,7 @@ class Liquidation(BaseModel):
|
|||||||
# purchaseAmount
|
# purchaseAmount
|
||||||
debt_purchase_amount: int
|
debt_purchase_amount: int
|
||||||
received_token_address: str
|
received_token_address: str
|
||||||
# received_amount: int
|
received_amount: int
|
||||||
protocol: Protocol
|
protocol: Protocol
|
||||||
transaction_hash: str
|
transaction_hash: str
|
||||||
block_number: str
|
block_number: str
|
||||||
|
Loading…
x
Reference in New Issue
Block a user