Compare commits

...

3 Commits

Author SHA1 Message Date
Luke Van Seters
25e1cbcf83 Add transfer classifiers to classifier specs. Implement for erc20 and weth 2021-09-28 13:04:46 -04:00
Luke Van Seters
f87016a561 Add field for transfer classifiers 2021-09-28 12:55:03 -04:00
Luke Van Seters
7645726708 Move classifier spec to its own schemas file 2021-09-28 12:50:50 -04:00
9 changed files with 67 additions and 20 deletions

View File

@ -1,6 +1,6 @@
from mev_inspect.schemas.classifier_specs import ClassifierSpec
from mev_inspect.schemas.classified_traces import ( from mev_inspect.schemas.classified_traces import (
Classification, Classification,
ClassifierSpec,
Protocol, Protocol,
) )

View File

@ -1,6 +1,6 @@
from mev_inspect.schemas.classifier_specs import ClassifierSpec
from mev_inspect.schemas.classified_traces import ( from mev_inspect.schemas.classified_traces import (
Classification, Classification,
ClassifierSpec,
Protocol, Protocol,
) )

View File

@ -1,5 +1,5 @@
from mev_inspect.schemas.classifier_specs import ClassifierSpec
from mev_inspect.schemas.classified_traces import ( from mev_inspect.schemas.classified_traces import (
ClassifierSpec,
Protocol, Protocol,
) )

View File

@ -1,15 +1,34 @@
from typing import Optional
from mev_inspect.schemas.classifier_specs import ClassifierSpec
from mev_inspect.schemas.classified_traces import ( from mev_inspect.schemas.classified_traces import (
Classification, Classification,
ClassifierSpec, DecodedCallTrace,
) )
from mev_inspect.schemas.transfers import ERC20Transfer
def classify_transfer(trace: DecodedCallTrace) -> Optional[ERC20Transfer]:
return ERC20Transfer(
block_number=trace.block_number,
transaction_hash=trace.transaction_hash,
trace_address=trace.trace_address,
amount=trace.inputs["amount"],
to_address=trace.inputs["recipient"],
from_address=trace.inputs.get("sender", trace.from_address),
token_address=trace.to_address,
)
ERC20_SPEC = ClassifierSpec( ERC20_SPEC = ClassifierSpec(
abi_name="ERC20", abi_name="ERC20",
transfer_classifiers={
"transferFrom(address,address,uint256)": classify_transfer,
"transfer(address,uint256)": classify_transfer,
},
classifications={ classifications={
"transferFrom(address,address,uint256)": Classification.transfer, "transferFrom(address,address,uint256)": Classification.transfer,
"transfer(address,uint256)": Classification.transfer, "transfer(address,uint256)": Classification.transfer,
"burn(address)": Classification.burn,
}, },
) )

View File

@ -1,6 +1,6 @@
from mev_inspect.schemas.classifier_specs import ClassifierSpec
from mev_inspect.schemas.classified_traces import ( from mev_inspect.schemas.classified_traces import (
Classification, Classification,
ClassifierSpec,
Protocol, Protocol,
) )

View File

@ -1,17 +1,39 @@
from typing import Optional
from mev_inspect.schemas.classifier_specs import ClassifierSpec
from mev_inspect.schemas.classified_traces import ( from mev_inspect.schemas.classified_traces import (
Classification, Classification,
ClassifierSpec, DecodedCallTrace,
Protocol, Protocol,
) )
from mev_inspect.schemas.transfers import ERC20Transfer
def classify_transfer(trace: DecodedCallTrace) -> Optional[ERC20Transfer]:
return ERC20Transfer(
block_number=trace.block_number,
transaction_hash=trace.transaction_hash,
trace_address=trace.trace_address,
amount=trace.inputs["wad"],
to_address=trace.inputs["dst"],
from_address=trace.from_address,
token_address=trace.to_address,
)
WETH_SPEC = ClassifierSpec( WETH_SPEC = ClassifierSpec(
abi_name="WETH9", abi_name="WETH9",
protocol=Protocol.weth, protocol=Protocol.weth,
valid_contract_addresses=["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"], valid_contract_addresses=["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"],
transfer_classifiers={
"transferFrom(address,address,uint256)": classify_transfer,
"transfer(address,uint256)": classify_transfer,
},
classifications={ classifications={
"transferFrom(address,address,uint256)": Classification.transfer, "transferFrom(address,address,uint256)": Classification.transfer,
"transfer(address,uint256)": Classification.transfer, "transfer(address,uint256)": Classification.transfer,
}, },
) )
WETH_CLASSIFIER_SPECS = [WETH_SPEC] WETH_CLASSIFIER_SPECS = [WETH_SPEC]

View File

@ -1,7 +1,5 @@
from mev_inspect.schemas.classified_traces import ( from mev_inspect.schemas.classifier_specs import ClassifierSpec
ClassifierSpec, from mev_inspect.schemas.classified_traces import Protocol
Protocol,
)
ZEROX_CONTRACT_SPECS = [ ZEROX_CONTRACT_SPECS = [

View File

@ -1,8 +1,6 @@
from enum import Enum from enum import Enum
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional
from pydantic import BaseModel
from .blocks import Trace from .blocks import Trace
@ -64,10 +62,3 @@ class DecodedCallTrace(CallTrace):
gas_used: Optional[int] gas_used: Optional[int]
function_name: Optional[str] function_name: Optional[str]
function_signature: 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] = {}

View File

@ -0,0 +1,17 @@
from typing import Callable, Dict, List, Optional
from pydantic import BaseModel
from .classified_traces import Classification, DecodedCallTrace, Protocol
from .transfers import ERC20Transfer
TransferClassifier = Callable[[DecodedCallTrace], Optional[ERC20Transfer]]
class ClassifierSpec(BaseModel):
abi_name: str
protocol: Optional[Protocol] = None
valid_contract_addresses: Optional[List[str]] = None
classifications: Dict[str, Classification] = {}
transfer_classifiers: Dict[str, TransferClassifier] = {}