Add Transfer schema + parse from trace
This commit is contained in:
parent
162443efd8
commit
4c42407faf
38
mev_inspect/schemas/transfers.py
Normal file
38
mev_inspect/schemas/transfers.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
from typing import List
|
||||||
|
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
from .classified_traces import Classification, ClassifiedTrace, Protocol
|
||||||
|
|
||||||
|
|
||||||
|
class Transfer(BaseModel):
|
||||||
|
transaction_hash: str
|
||||||
|
trace_address: List[int]
|
||||||
|
from_address: str
|
||||||
|
to_address: str
|
||||||
|
amount: int
|
||||||
|
token_address: str
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_trace(cls, trace: ClassifiedTrace) -> "Transfer":
|
||||||
|
if trace.classification != Classification.transfer or trace.inputs is None:
|
||||||
|
raise ValueError("Invalid transfer")
|
||||||
|
|
||||||
|
if trace.protocol == Protocol.weth:
|
||||||
|
return cls(
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return cls(
|
||||||
|
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,
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user