From d2c397f2123790bc9bc2e2bd7b76cda2a125393d Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Wed, 6 Oct 2021 14:53:38 -0400 Subject: [PATCH] Change classifications => classifiers --- mev_inspect/classifiers/specs/aave.py | 12 +++++++++--- mev_inspect/classifiers/specs/balancer.py | 16 ++++++++++++---- mev_inspect/classifiers/specs/curve.py | 5 ++++- mev_inspect/classifiers/specs/erc20.py | 17 +++++++++++++---- mev_inspect/classifiers/specs/uniswap.py | 17 ++++++++++++----- mev_inspect/classifiers/specs/weth.py | 16 ++++++++++++---- mev_inspect/classifiers/specs/zero_ex.py | 4 +++- mev_inspect/classifiers/trace.py | 7 +++++-- mev_inspect/schemas/classified_traces.py | 9 --------- mev_inspect/schemas/classifiers.py | 16 ++++++++++++++++ 10 files changed, 86 insertions(+), 33 deletions(-) create mode 100644 mev_inspect/schemas/classifiers.py diff --git a/mev_inspect/classifiers/specs/aave.py b/mev_inspect/classifiers/specs/aave.py index c12e785..f8613b1 100644 --- a/mev_inspect/classifiers/specs/aave.py +++ b/mev_inspect/classifiers/specs/aave.py @@ -1,14 +1,20 @@ from mev_inspect.schemas.classified_traces import ( Classification, - ClassifierSpec, Protocol, ) +from mev_inspect.schemas.classifiers import ( + ClassifierSpec, + Classifier, +) + AAVE_SPEC = ClassifierSpec( abi_name="AaveLendingPool", protocol=Protocol.aave, - classifications={ - "liquidationCall(address,address,address,uint256,bool)": Classification.liquidate, + classifiers={ + "liquidationCall(address,address,address,uint256,bool)": Classifier( + classification=Classification.liquidate, + ) }, ) diff --git a/mev_inspect/classifiers/specs/balancer.py b/mev_inspect/classifiers/specs/balancer.py index 835d1bf..d9c01f9 100644 --- a/mev_inspect/classifiers/specs/balancer.py +++ b/mev_inspect/classifiers/specs/balancer.py @@ -1,16 +1,24 @@ from mev_inspect.schemas.classified_traces import ( Classification, - ClassifierSpec, Protocol, ) +from mev_inspect.schemas.classifiers import ( + ClassifierSpec, + Classifier, +) + BALANCER_V1_SPECS = [ ClassifierSpec( abi_name="BPool", protocol=Protocol.balancer_v1, - classifications={ - "swapExactAmountIn(address,uint256,address,uint256,uint256)": Classification.swap, - "swapExactAmountOut(address,uint256,address,uint256,uint256)": Classification.swap, + classifiers={ + "swapExactAmountIn(address,uint256,address,uint256,uint256)": Classifier( + classification=Classification.swap, + ), + "swapExactAmountOut(address,uint256,address,uint256,uint256)": Classifier( + classification=Classification.swap, + ), }, ), ] diff --git a/mev_inspect/classifiers/specs/curve.py b/mev_inspect/classifiers/specs/curve.py index 79610f9..a631b8c 100644 --- a/mev_inspect/classifiers/specs/curve.py +++ b/mev_inspect/classifiers/specs/curve.py @@ -1,8 +1,11 @@ from mev_inspect.schemas.classified_traces import ( - ClassifierSpec, Protocol, ) +from mev_inspect.schemas.classifiers import ( + ClassifierSpec, +) + """ Deployment addresses found here https://curve.readthedocs.io/ref-addresses.html diff --git a/mev_inspect/classifiers/specs/erc20.py b/mev_inspect/classifiers/specs/erc20.py index 02cd3ae..8e1ef4f 100644 --- a/mev_inspect/classifiers/specs/erc20.py +++ b/mev_inspect/classifiers/specs/erc20.py @@ -1,15 +1,24 @@ from mev_inspect.schemas.classified_traces import ( Classification, +) +from mev_inspect.schemas.classifiers import ( ClassifierSpec, + Classifier, ) ERC20_SPEC = ClassifierSpec( abi_name="ERC20", - classifications={ - "transferFrom(address,address,uint256)": Classification.transfer, - "transfer(address,uint256)": Classification.transfer, - "burn(address)": Classification.burn, + classifiers={ + "transferFrom(address,address,uint256)": Classifier( + classification=Classification.transfer, + ), + "transfer(address,uint256)": Classifier( + classification=Classification.transfer, + ), + "burn(address)": Classifier( + classification=Classification.burn, + ), }, ) diff --git a/mev_inspect/classifiers/specs/uniswap.py b/mev_inspect/classifiers/specs/uniswap.py index e6c9f5a..d02e40d 100644 --- a/mev_inspect/classifiers/specs/uniswap.py +++ b/mev_inspect/classifiers/specs/uniswap.py @@ -1,8 +1,11 @@ from mev_inspect.schemas.classified_traces import ( Classification, - ClassifierSpec, Protocol, ) +from mev_inspect.schemas.classifiers import ( + ClassifierSpec, + Classifier, +) UNISWAP_V3_CONTRACT_SPECS = [ @@ -66,8 +69,10 @@ UNISWAP_V3_CONTRACT_SPECS = [ UNISWAP_V3_GENERAL_SPECS = [ ClassifierSpec( abi_name="UniswapV3Pool", - classifications={ - "swap(address,bool,int256,uint160,bytes)": Classification.swap, + classifiers={ + "swap(address,bool,int256,uint160,bytes)": Classifier( + classification=Classification.swap, + ) }, ), ClassifierSpec( @@ -97,8 +102,10 @@ UNISWAPPY_V2_CONTRACT_SPECS = [ UNISWAPPY_V2_PAIR_SPEC = ClassifierSpec( abi_name="UniswapV2Pair", - classifications={ - "swap(uint256,uint256,address,bytes)": Classification.swap, + classifiers={ + "swap(uint256,uint256,address,bytes)": Classifier( + classification=Classification.swap, + ), }, ) diff --git a/mev_inspect/classifiers/specs/weth.py b/mev_inspect/classifiers/specs/weth.py index df85790..f2f68b8 100644 --- a/mev_inspect/classifiers/specs/weth.py +++ b/mev_inspect/classifiers/specs/weth.py @@ -1,16 +1,24 @@ from mev_inspect.schemas.classified_traces import ( Classification, - ClassifierSpec, Protocol, ) +from mev_inspect.schemas.classifiers import ( + ClassifierSpec, + Classifier, +) + WETH_SPEC = ClassifierSpec( abi_name="WETH9", protocol=Protocol.weth, valid_contract_addresses=["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"], - classifications={ - "transferFrom(address,address,uint256)": Classification.transfer, - "transfer(address,uint256)": Classification.transfer, + classifiers={ + "transferFrom(address,address,uint256)": Classifier( + classification=Classification.transfer, + ), + "transfer(address,uint256)": Classifier( + classification=Classification.transfer, + ), }, ) diff --git a/mev_inspect/classifiers/specs/zero_ex.py b/mev_inspect/classifiers/specs/zero_ex.py index 4f47a03..f558b1d 100644 --- a/mev_inspect/classifiers/specs/zero_ex.py +++ b/mev_inspect/classifiers/specs/zero_ex.py @@ -1,7 +1,9 @@ from mev_inspect.schemas.classified_traces import ( - ClassifierSpec, Protocol, ) +from mev_inspect.schemas.classifiers import ( + ClassifierSpec, +) ZEROX_CONTRACT_SPECS = [ diff --git a/mev_inspect/classifiers/trace.py b/mev_inspect/classifiers/trace.py index 9968eb6..841ca29 100644 --- a/mev_inspect/classifiers/trace.py +++ b/mev_inspect/classifiers/trace.py @@ -67,8 +67,11 @@ class TraceClassifier: if call_data is not None: signature = call_data.function_signature - classification = spec.classifications.get( - signature, Classification.unknown + classifier = spec.classifiers.get(signature) + classification = ( + Classification.unknown + if classifier is None + else classifier.classification ) return DecodedCallTrace( diff --git a/mev_inspect/schemas/classified_traces.py b/mev_inspect/schemas/classified_traces.py index d50cb8b..e226edf 100644 --- a/mev_inspect/schemas/classified_traces.py +++ b/mev_inspect/schemas/classified_traces.py @@ -1,8 +1,6 @@ from enum import Enum from typing import Any, Dict, List, Optional -from pydantic import BaseModel - from .blocks import Trace @@ -64,10 +62,3 @@ class DecodedCallTrace(CallTrace): gas_used: Optional[int] function_name: Optional[str] function_signature: Optional[str] - - -class ClassifierSpec(BaseModel): - abi_name: str - protocol: Optional[Protocol] = None - valid_contract_addresses: Optional[List[str]] = None - classifications: Dict[str, Classification] = {} diff --git a/mev_inspect/schemas/classifiers.py b/mev_inspect/schemas/classifiers.py new file mode 100644 index 0000000..006ab58 --- /dev/null +++ b/mev_inspect/schemas/classifiers.py @@ -0,0 +1,16 @@ +from typing import Dict, List, Optional + +from pydantic import BaseModel + +from .classified_traces import Classification, Protocol + + +class Classifier(BaseModel): + classification: Classification + + +class ClassifierSpec(BaseModel): + abi_name: str + protocol: Optional[Protocol] = None + valid_contract_addresses: Optional[List[str]] = None + classifiers: Dict[str, Classifier] = {}