Add support for ETH transfers to miner
This commit is contained in:
parent
54ebe78460
commit
0b74331235
32
mev_inspect/miner_payments.py
Normal file
32
mev_inspect/miner_payments.py
Normal file
@ -0,0 +1,32 @@
|
||||
from typing import Dict, List
|
||||
|
||||
from mev_inspect.schemas.classified_traces import ClassifiedTrace
|
||||
from mev_inspect.schemas.miner_payments import MinerPayment
|
||||
from mev_inspect.transfers import (
|
||||
get_eth_transfers,
|
||||
filter_transfers,
|
||||
)
|
||||
|
||||
|
||||
def get_miner_payments(
|
||||
miner_address: str, traces: List[ClassifiedTrace]
|
||||
) -> List[MinerPayment]:
|
||||
eth_transfers = get_eth_transfers(traces)
|
||||
miner_eth_transfers = filter_transfers(
|
||||
eth_transfers, to_address=miner_address.lower()
|
||||
)
|
||||
|
||||
eth_by_transaction: Dict[str, int] = {}
|
||||
for transfer in miner_eth_transfers:
|
||||
existing_amount = eth_by_transaction.get(transfer.transaction_hash, 0)
|
||||
eth_by_transaction[transfer.transaction_hash] = (
|
||||
existing_amount + transfer.amount
|
||||
)
|
||||
|
||||
return [
|
||||
MinerPayment(
|
||||
transaction_hash=transaction_hash,
|
||||
total_eth_transfer_payment=eth_amount,
|
||||
)
|
||||
for transaction_hash, eth_amount in eth_by_transaction.items()
|
||||
]
|
6
mev_inspect/schemas/miner_payments.py
Normal file
6
mev_inspect/schemas/miner_payments.py
Normal file
@ -0,0 +1,6 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class MinerPayment(BaseModel):
|
||||
transaction_hash: str
|
||||
total_eth_transfer_payment: int
|
@ -1,4 +1,4 @@
|
||||
from typing import List
|
||||
from typing import List, TypeVar
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
@ -13,6 +13,10 @@ class Transfer(BaseModel):
|
||||
amount: int
|
||||
|
||||
|
||||
# To preserve the specific Transfer type
|
||||
TransferGeneric = TypeVar("TransferGeneric", bound="Transfer")
|
||||
|
||||
|
||||
class EthTransfer(Transfer):
|
||||
@classmethod
|
||||
def from_trace(cls, trace: ClassifiedTrace) -> "EthTransfer":
|
||||
|
@ -1,7 +1,7 @@
|
||||
from typing import Dict, List, Optional
|
||||
from typing import Dict, List, Optional, Sequence
|
||||
|
||||
from mev_inspect.schemas.classified_traces import Classification, ClassifiedTrace
|
||||
from mev_inspect.schemas.transfers import ERC20Transfer, EthTransfer, Transfer
|
||||
from mev_inspect.schemas.transfers import ERC20Transfer, EthTransfer, TransferGeneric
|
||||
from mev_inspect.traces import is_child_trace_address, get_child_traces
|
||||
|
||||
|
||||
@ -40,10 +40,10 @@ def get_child_transfers(
|
||||
|
||||
|
||||
def filter_transfers(
|
||||
transfers: List[Transfer],
|
||||
transfers: Sequence[TransferGeneric],
|
||||
to_address: Optional[str] = None,
|
||||
from_address: Optional[str] = None,
|
||||
) -> List[Transfer]:
|
||||
) -> List[TransferGeneric]:
|
||||
filtered_transfers = []
|
||||
|
||||
for transfer in transfers:
|
||||
|
@ -18,6 +18,7 @@ from mev_inspect.classifiers.specs import ALL_CLASSIFIER_SPECS
|
||||
from mev_inspect.classifiers.trace import TraceClassifier
|
||||
from mev_inspect.crud.swaps import delete_swaps_for_block, write_swaps
|
||||
from mev_inspect.db import get_session
|
||||
from mev_inspect.miner_payments import get_miner_payments
|
||||
from mev_inspect.swaps import get_swaps
|
||||
|
||||
|
||||
@ -50,7 +51,15 @@ def inspect_many_blocks(after_block: int, before_block: int, rpc: str, cache: bo
|
||||
if not cache:
|
||||
click.echo("Skipping cache")
|
||||
|
||||
for block_number in range(after_block + 1, before_block):
|
||||
for i, block_number in enumerate(range(after_block, before_block)):
|
||||
block_message = (
|
||||
f"Running for {block_number} ({i+1}/{before_block - after_block})"
|
||||
)
|
||||
dashes = "-" * len(block_message)
|
||||
click.echo(dashes)
|
||||
click.echo(block_message)
|
||||
click.echo(dashes)
|
||||
|
||||
_inspect_block(
|
||||
base_provider,
|
||||
block_number,
|
||||
@ -64,18 +73,12 @@ def _inspect_block(
|
||||
base_provider,
|
||||
block_number: int,
|
||||
should_cache: bool,
|
||||
should_print_stats: bool = True,
|
||||
should_print_stats: bool = False,
|
||||
should_write_classified_traces: bool = True,
|
||||
should_write_swaps: bool = True,
|
||||
should_write_arbitrages: bool = True,
|
||||
):
|
||||
|
||||
block_message = f"Running for {block_number}"
|
||||
dashes = "-" * len(block_message)
|
||||
click.echo(dashes)
|
||||
click.echo(block_message)
|
||||
click.echo(dashes)
|
||||
|
||||
block_data = block.create_from_block_number(
|
||||
block_number, base_provider, should_cache
|
||||
)
|
||||
@ -101,6 +104,10 @@ def _inspect_block(
|
||||
delete_classified_traces_for_block(db_session, block_number)
|
||||
write_classified_traces(db_session, classified_traces)
|
||||
|
||||
miner_payments = get_miner_payments(block_data.miner, classified_traces)
|
||||
click.echo("Miner payments:")
|
||||
click.echo(json.dumps([p.dict() for p in miner_payments], indent=4))
|
||||
|
||||
swaps = get_swaps(classified_traces)
|
||||
click.echo(f"Found {len(swaps)} swaps")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user