Add support for base fee
This commit is contained in:
parent
1aabb12105
commit
fcdfad7963
@ -3,6 +3,7 @@ from typing import List
|
|||||||
|
|
||||||
from web3 import Web3
|
from web3 import Web3
|
||||||
|
|
||||||
|
from mev_inspect.fees import fetch_base_fee_per_gas
|
||||||
from mev_inspect.schemas import Block, Trace, TraceType
|
from mev_inspect.schemas import Block, Trace, TraceType
|
||||||
from mev_inspect.schemas.receipts import Receipt
|
from mev_inspect.schemas.receipts import Receipt
|
||||||
|
|
||||||
@ -41,10 +42,12 @@ def fetch_block(w3, base_provider, block_number: int) -> Block:
|
|||||||
Receipt(**receipt) for receipt in receipts_json["result"]
|
Receipt(**receipt) for receipt in receipts_json["result"]
|
||||||
]
|
]
|
||||||
traces = [Trace(**trace_json) for trace_json in traces_json]
|
traces = [Trace(**trace_json) for trace_json in traces_json]
|
||||||
|
base_fee_per_gas = fetch_base_fee_per_gas(w3, block_number)
|
||||||
|
|
||||||
return Block(
|
return Block(
|
||||||
block_number=block_number,
|
block_number=block_number,
|
||||||
miner=block_json["miner"],
|
miner=block_json["miner"],
|
||||||
|
base_fee_per_gas=base_fee_per_gas,
|
||||||
traces=traces,
|
traces=traces,
|
||||||
receipts=receipts,
|
receipts=receipts,
|
||||||
)
|
)
|
||||||
|
9
mev_inspect/fees.py
Normal file
9
mev_inspect/fees.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from web3 import Web3
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_base_fee_per_gas(w3: Web3, block_number: int) -> int:
|
||||||
|
base_fees = w3.eth.fee_history(1, block_number)["baseFeePerGas"]
|
||||||
|
if len(base_fees) == 0:
|
||||||
|
raise RuntimeError("Unexpected error - no fees returned")
|
||||||
|
|
||||||
|
return base_fees[0]
|
@ -11,7 +11,10 @@ from mev_inspect.transfers import (
|
|||||||
|
|
||||||
|
|
||||||
def get_miner_payments(
|
def get_miner_payments(
|
||||||
miner_address: str, traces: List[ClassifiedTrace], receipts: List[Receipt]
|
miner_address: str,
|
||||||
|
base_fee_per_gas: int,
|
||||||
|
traces: List[ClassifiedTrace],
|
||||||
|
receipts: List[Receipt],
|
||||||
) -> List[MinerPayment]:
|
) -> List[MinerPayment]:
|
||||||
miner_payments = []
|
miner_payments = []
|
||||||
|
|
||||||
@ -38,6 +41,7 @@ def get_miner_payments(
|
|||||||
transaction_index=receipt.transaction_index,
|
transaction_index=receipt.transaction_index,
|
||||||
gas_price=receipt.effective_gas_price,
|
gas_price=receipt.effective_gas_price,
|
||||||
gas_price_with_coinbase_transfer=gas_price_with_coinbase_transfer,
|
gas_price_with_coinbase_transfer=gas_price_with_coinbase_transfer,
|
||||||
|
base_fee_per_gas=base_fee_per_gas,
|
||||||
gas_used=receipt.gas_used,
|
gas_used=receipt.gas_used,
|
||||||
coinbase_transfer=coinbase_transfer,
|
coinbase_transfer=coinbase_transfer,
|
||||||
)
|
)
|
||||||
|
@ -60,6 +60,7 @@ class Trace(CamelModel):
|
|||||||
class Block(Web3Model):
|
class Block(Web3Model):
|
||||||
block_number: int
|
block_number: int
|
||||||
miner: str
|
miner: str
|
||||||
|
base_fee_per_gas: int
|
||||||
traces: List[Trace]
|
traces: List[Trace]
|
||||||
receipts: List[Receipt]
|
receipts: List[Receipt]
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ class MinerPayment(BaseModel):
|
|||||||
transaction_index: int
|
transaction_index: int
|
||||||
miner_address: str
|
miner_address: str
|
||||||
coinbase_transfer: int
|
coinbase_transfer: int
|
||||||
|
base_fee_per_gas: int
|
||||||
gas_price: int
|
gas_price: int
|
||||||
gas_price_with_coinbase_transfer: int
|
gas_price_with_coinbase_transfer: int
|
||||||
gas_used: int
|
gas_used: int
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from typing import Optional
|
||||||
|
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
|
|
||||||
from mev_inspect.utils import hex_to_int
|
from mev_inspect.utils import hex_to_int
|
||||||
@ -12,7 +14,7 @@ class Receipt(CamelModel):
|
|||||||
gas_used: int
|
gas_used: int
|
||||||
effective_gas_price: int
|
effective_gas_price: int
|
||||||
cumulative_gas_used: int
|
cumulative_gas_used: int
|
||||||
to: str
|
to: Optional[str]
|
||||||
|
|
||||||
@validator(
|
@validator(
|
||||||
"block_number",
|
"block_number",
|
||||||
|
@ -3,7 +3,7 @@ import json
|
|||||||
import click
|
import click
|
||||||
from web3 import Web3
|
from web3 import Web3
|
||||||
|
|
||||||
from mev_inspect import block
|
from mev_inspect.block import create_from_block_number
|
||||||
from mev_inspect.crud.arbitrages import (
|
from mev_inspect.crud.arbitrages import (
|
||||||
delete_arbitrages_for_block,
|
delete_arbitrages_for_block,
|
||||||
write_arbitrages,
|
write_arbitrages,
|
||||||
@ -83,23 +83,17 @@ def _inspect_block(
|
|||||||
should_write_arbitrages: bool = True,
|
should_write_arbitrages: bool = True,
|
||||||
should_print_miner_payments: bool = True,
|
should_print_miner_payments: bool = True,
|
||||||
):
|
):
|
||||||
block_data = block.create_from_block_number(
|
block = create_from_block_number(base_provider, w3, block_number, should_cache)
|
||||||
base_provider, w3, block_number, should_cache
|
|
||||||
)
|
|
||||||
|
|
||||||
click.echo(f"Total traces: {len(block_data.traces)}")
|
click.echo(f"Total traces: {len(block.traces)}")
|
||||||
|
|
||||||
total_transactions = len(
|
total_transactions = len(
|
||||||
set(
|
set(t.transaction_hash for t in block.traces if t.transaction_hash is not None)
|
||||||
t.transaction_hash
|
|
||||||
for t in block_data.traces
|
|
||||||
if t.transaction_hash is not None
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
click.echo(f"Total transactions: {total_transactions}")
|
click.echo(f"Total transactions: {total_transactions}")
|
||||||
|
|
||||||
trace_clasifier = TraceClassifier(ALL_CLASSIFIER_SPECS)
|
trace_clasifier = TraceClassifier(ALL_CLASSIFIER_SPECS)
|
||||||
classified_traces = trace_clasifier.classify(block_data.traces)
|
classified_traces = trace_clasifier.classify(block.traces)
|
||||||
click.echo(f"Returned {len(classified_traces)} classified traces")
|
click.echo(f"Returned {len(classified_traces)} classified traces")
|
||||||
|
|
||||||
db_session = get_session()
|
db_session = get_session()
|
||||||
@ -127,7 +121,7 @@ def _inspect_block(
|
|||||||
click.echo(json.dumps(stats, indent=4))
|
click.echo(json.dumps(stats, indent=4))
|
||||||
|
|
||||||
miner_payments = get_miner_payments(
|
miner_payments = get_miner_payments(
|
||||||
block_data.miner, classified_traces, block_data.receipts
|
block.miner, block.base_fee_per_gas, classified_traces, block.receipts
|
||||||
)
|
)
|
||||||
|
|
||||||
if should_print_miner_payments:
|
if should_print_miner_payments:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user