Merge pull request #56 from flashbots/block-receipts

Add an object for block receipts
This commit is contained in:
Robert Miller 2021-08-25 17:12:50 -04:00 committed by GitHub
commit c7054aa447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 46 additions and 46323 deletions

View File

@ -4,6 +4,7 @@ from typing import Any, Dict, List
from web3 import Web3
from mev_inspect.schemas import Block, Trace, TraceType
from mev_inspect.schemas.receipts import Receipt
cache_directory = "./cache"
@ -46,6 +47,9 @@ def fetch_block(w3, base_provider, block_number: int) -> Block:
block_receipts_raw = base_provider.make_request(
"eth_getBlockReceipts", [block_number]
)
receipts: List[Receipt] = [
Receipt(**receipt) for receipt in block_receipts_raw["result"]
]
## Trace the whole block, return those calls
traces_json = w3.parity.trace_block(block_number)
@ -63,7 +67,7 @@ def fetch_block(w3, base_provider, block_number: int) -> Block:
return Block(
block_number=block_number,
data=block_data,
receipts=block_receipts_raw,
receipts=receipts,
traces=traces,
logs=block_logs,
transaction_hashes=transaction_hashes,

View File

@ -4,6 +4,8 @@ from typing import Dict, List, Optional
from pydantic import validator
from mev_inspect.utils import hex_to_int
from .receipts import Receipt
from .utils import CamelModel, Web3Model
@ -60,7 +62,7 @@ class Block(Web3Model):
traces: List[Trace]
data: dict
logs: List[dict]
receipts: dict
receipts: List[Receipt]
transaction_hashes: List[str]
txs_gas_data: Dict[str, dict]

View File

@ -0,0 +1,28 @@
from pydantic import validator
from mev_inspect.utils import hex_to_int
from .utils import CamelModel
class Receipt(CamelModel):
block_number: int
transaction_hash: str
transaction_index: int
gas_used: int
effective_gas_price: int
cumulative_gas_used: int
to: str
@validator(
"block_number",
"transaction_index",
"gas_used",
"effective_gas_price",
"cumulative_gas_used",
pre=True,
)
def maybe_hex_to_int(v):
if isinstance(v, str):
return hex_to_int(v)
return v

View File

@ -62,9 +62,9 @@ def is_known_router_address(address):
# we're interested in the to address to run token flow on it as well
def get_tx_to_address(tx_hash, block) -> Optional[str]:
for receipt in block.receipts["result"]:
if receipt["transactionHash"] == tx_hash:
return receipt["to"]
for receipt in block.receipts:
if receipt.transaction_hash == tx_hash:
return receipt.to
return None

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -7,14 +7,15 @@ from .utils import load_test_block
def test_arbitrage_real_block():
block = load_test_block(12914994)
block = load_test_block(12914944)
trace_clasifier = TraceClassifier(ALL_CLASSIFIER_SPECS)
classified_traces = trace_clasifier.classify(block.traces)
swaps = get_swaps(classified_traces)
arbitrages = get_arbitrages(swaps)
assert len(swaps) == 51
arbitrages = get_arbitrages(list(swaps))
assert len(arbitrages) == 1
arbitrage = arbitrages[0]