feat: Add initial atomicMatch logic for OpenSea
This commit is contained in:
parent
24951891ca
commit
3663d075d9
64
mev_inspect/classifiers/specs/opensea.py
Normal file
64
mev_inspect/classifiers/specs/opensea.py
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
from mev_inspect.schemas.classified_traces import (
|
||||||
|
DecodedCallTrace,
|
||||||
|
Protocol,
|
||||||
|
)
|
||||||
|
from mev_inspect.schemas.classifiers import (
|
||||||
|
ClassifierSpec,
|
||||||
|
AtomicMatchClassifier,
|
||||||
|
)
|
||||||
|
|
||||||
|
OPENSEA_ATOMIC_MATCH_ABI_NAME='atomicMatch_'
|
||||||
|
|
||||||
|
OPENSEA_SPEC = [
|
||||||
|
ClassifierSpec(
|
||||||
|
abi_name="atomicMatch_",
|
||||||
|
protocol=Protocol.opensea,
|
||||||
|
valid_contract_addresses=["0x7be8076f4ea4a4ad08075c2508e481d6c946d12b"],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
UNISWAP_V3_GENERAL_SPECS = [
|
||||||
|
ClassifierSpec(
|
||||||
|
abi_name=UNISWAP_V3_POOL_ABI_NAME,
|
||||||
|
classifiers={
|
||||||
|
"swap(address,bool,int256,uint160,bytes)": UniswapV3SwapClassifier,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ClassifierSpec(
|
||||||
|
abi_name="IUniswapV3SwapCallback",
|
||||||
|
),
|
||||||
|
ClassifierSpec(
|
||||||
|
abi_name="IUniswapV3MintCallback",
|
||||||
|
),
|
||||||
|
ClassifierSpec(
|
||||||
|
abi_name="IUniswapV3FlashCallback",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
UNISWAPPY_V2_CONTRACT_SPECS = [
|
||||||
|
ClassifierSpec(
|
||||||
|
abi_name="UniswapV2Router",
|
||||||
|
protocol=Protocol.uniswap_v2,
|
||||||
|
valid_contract_addresses=["0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"],
|
||||||
|
),
|
||||||
|
ClassifierSpec(
|
||||||
|
abi_name="UniswapV2Router",
|
||||||
|
protocol=Protocol.sushiswap,
|
||||||
|
valid_contract_addresses=["0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F"],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
UNISWAPPY_V2_PAIR_SPEC = ClassifierSpec(
|
||||||
|
abi_name=UNISWAP_V2_PAIR_ABI_NAME,
|
||||||
|
classifiers={
|
||||||
|
"swap(uint256,uint256,address,bytes)": UniswapV2SwapClassifier,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
UNISWAP_CLASSIFIER_SPECS = [
|
||||||
|
*UNISWAP_V3_CONTRACT_SPECS,
|
||||||
|
*UNISWAPPY_V2_CONTRACT_SPECS,
|
||||||
|
*UNISWAP_V3_GENERAL_SPECS,
|
||||||
|
UNISWAPPY_V2_PAIR_SPEC,
|
||||||
|
]
|
26
mev_inspect/crud/atomicmatch.py
Normal file
26
mev_inspect/crud/atomicmatch.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import json
|
||||||
|
from typing import list
|
||||||
|
|
||||||
|
from mev_inspect.models.atomicmatch import AtomicMatchModel
|
||||||
|
from mev_inspect.schemas.atomicmatch import AtomicMatch
|
||||||
|
|
||||||
|
def delete_atomicmatch_for_block(
|
||||||
|
db_session,
|
||||||
|
block_number: int,
|
||||||
|
) -> None:
|
||||||
|
(
|
||||||
|
db_session.query(AtomicMatchModel)
|
||||||
|
.filter(AtomicMatchModel.block_number == block_number)
|
||||||
|
.delete()
|
||||||
|
)
|
||||||
|
|
||||||
|
db_session.commit()
|
||||||
|
|
||||||
|
def write_atomicmatch(
|
||||||
|
db_session,
|
||||||
|
atomicmatches: List[AtomicMatch],
|
||||||
|
) -> None:
|
||||||
|
models = [AtomicMatchModel(**json.loads(atomicmatch.json())) for atomicmatch in atomicmatches]
|
||||||
|
|
||||||
|
db_session.bulk_save_objects(models)
|
||||||
|
db_session.commit()
|
@ -24,6 +24,10 @@ from mev_inspect.crud.liquidations import (
|
|||||||
delete_liquidations_for_block,
|
delete_liquidations_for_block,
|
||||||
write_liquidations,
|
write_liquidations,
|
||||||
)
|
)
|
||||||
|
from mev_inspect.crud.atomicmatch import (
|
||||||
|
delete_atomicmatch_for_block,
|
||||||
|
write_atomicmatch,
|
||||||
|
)
|
||||||
from mev_inspect.miner_payments import get_miner_payments
|
from mev_inspect.miner_payments import get_miner_payments
|
||||||
from mev_inspect.swaps import get_swaps
|
from mev_inspect.swaps import get_swaps
|
||||||
from mev_inspect.transfers import get_transfers
|
from mev_inspect.transfers import get_transfers
|
||||||
|
17
mev_inspect/models/atomicmatch.py
Normal file
17
mev_inspect/models/atomicmatch.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from sqlalchemy import Column, Numeric, String, Integer, ARRAY
|
||||||
|
|
||||||
|
from .base import Base
|
||||||
|
|
||||||
|
|
||||||
|
class AtomicMatchModel(Base):
|
||||||
|
__tablename__ = "atomic_match"
|
||||||
|
|
||||||
|
block_number = Column(Numeric, nullable=False)
|
||||||
|
transaction_hash = Column(String, primary_key=True)
|
||||||
|
protocol = Column(String, nullable=True)
|
||||||
|
from_address = Column(String, nullable=False)
|
||||||
|
to_address = Column(String, nullable=False)
|
||||||
|
token_address = Column(String, nullable=False)
|
||||||
|
amount = Column(Numeric, nullable=False)
|
||||||
|
metadata = Column(ARRAY(String), nullable=False)
|
||||||
|
error = Column(String, nullable=True)
|
14
mev_inspect/schemas/atomicmatch.py
Normal file
14
mev_inspect/schemas/atomicmatch.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from typing import list
|
||||||
|
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
ETH_TOKEN_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
|
||||||
|
|
||||||
|
class AtomicMatch(BaseModel):
|
||||||
|
block_number: int
|
||||||
|
transaction_hash: str
|
||||||
|
protocol: str
|
||||||
|
from_address: str
|
||||||
|
to_address: str
|
||||||
|
amount: str
|
||||||
|
metadata: List[str]
|
@ -10,6 +10,7 @@ class Classification(Enum):
|
|||||||
transfer = "transfer"
|
transfer = "transfer"
|
||||||
liquidate = "liquidate"
|
liquidate = "liquidate"
|
||||||
seize = "seize"
|
seize = "seize"
|
||||||
|
atomicmatch = "atomicmatch"
|
||||||
|
|
||||||
|
|
||||||
class Protocol(Enum):
|
class Protocol(Enum):
|
||||||
@ -22,6 +23,7 @@ class Protocol(Enum):
|
|||||||
zero_ex = "0x"
|
zero_ex = "0x"
|
||||||
balancer_v1 = "balancer_v1"
|
balancer_v1 = "balancer_v1"
|
||||||
compound_v2 = "compound_v2"
|
compound_v2 = "compound_v2"
|
||||||
|
opensea = "opensea"
|
||||||
|
|
||||||
|
|
||||||
class ClassifiedTrace(Trace):
|
class ClassifiedTrace(Trace):
|
||||||
|
@ -41,6 +41,10 @@ class LiquidationClassifier(Classifier):
|
|||||||
def get_classification() -> Classification:
|
def get_classification() -> Classification:
|
||||||
return Classification.liquidate
|
return Classification.liquidate
|
||||||
|
|
||||||
|
class AtomicMatchClassifier(Classifier):
|
||||||
|
@staticmethod
|
||||||
|
def get_classification() -> Classification:
|
||||||
|
return Classification.atomicmatch
|
||||||
|
|
||||||
class SeizeClassifier(Classifier):
|
class SeizeClassifier(Classifier):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
Loading…
x
Reference in New Issue
Block a user