Added liquidation_inspector.py, aave protocol and classifier spec

This commit is contained in:
Guilherme Peyrelongue Heise 2021-08-03 12:55:53 -04:00
parent f903fff3c9
commit 1201623c1f
3 changed files with 71 additions and 0 deletions

61
liquidation_inspector.py Normal file
View File

@ -0,0 +1,61 @@
import json
from typing import Optional
from web3 import Web3
from typing import List, Optional
from mev_inspect import utils
from mev_inspect.config import load_config
from mev_inspect.schemas.blocks import NestedTrace, TraceType
from mev_inspect.schemas.classifications import Classification
from mev_inspect.schemas.strategy import Strategy, Liquidation
from .base import StrategyInspector
class LiquidationInspector(StrategyInspector):
def __init__(self):
self.result = []
# Inspect list of classified traces and identify liquidation
def inspect(self, traces):
event = []
# For each trace
for i in range(1, len(traces)):
trace = traces[i]
# Liquidation condition
if trace.classification == Classification.liquidate:
# Collateral data from the liquidation.
# The inputs will differ by DEX, this is AAVE
for i in trace.inputs:
if( i["name"] == '_purchaseAmount'):
value = trace.inputs[i]
elif (i["name"] == '_collateral'):
collateral_type = trace.inputs[i]
elif (i["name"] == '_reserve'):
collateral_source = trace.inputs[i]
# Define the address of the liquidator
liquidator = trace.from_address
# Find a transfer before liquidation with a to_address corresponding to the liquidator
for trace in traces[:i]:
if (trace.classification == Classification.transfer & trace.to_address == liquidator):
profit =
#Calculate profit
# Tag liquidation
event.append(Strategy(strategy=StategyType.liquidation,
traces=[trace],
protocols=[trace.protocol]))
return result

View File

@ -99,10 +99,19 @@ ERC20_SPEC = ClassifierSpec(
},
)
AAVE_SPEC = ClassifierSpec(
abi_name="AaveLendingPool",
protocol= Protocol.aave
classifications={
"liquidationCall(address,address,address,uint256,bool)": Classification.liquidate,
},
)
CLASSIFIER_SPECS = [
*UNISWAP_V3_CONTRACT_SPECS,
*UNISWAPPY_V2_CONTRACT_SPECS,
AAVE_SPEC,
ERC20_SPEC,
UNISWAP_V3_POOL_SPEC,
UNISWAPPY_V2_PAIR_SPEC,

View File

@ -17,6 +17,7 @@ class Protocol(Enum):
uniswap_v2 = "uniswap_v2"
uniswap_v3 = "uniswap_v3"
sushiswap = "sushiswap"
aave = "aave"
class ClassifiedTrace(BaseModel):