Break out v2 into a function. Handle sender parameter
This commit is contained in:
parent
ea07eb3a8f
commit
a865534187
@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
from typing import Dict, List, Optional
|
from typing import Dict, List, Optional
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
@ -58,7 +59,7 @@ def _get_arbitrages_for_transaction(
|
|||||||
traces: List[ClassifiedTrace],
|
traces: List[ClassifiedTrace],
|
||||||
) -> List[Arbitrage]:
|
) -> List[Arbitrage]:
|
||||||
swaps = _get_swaps(traces)
|
swaps = _get_swaps(traces)
|
||||||
print(swaps)
|
print(json.dumps([swap.dict() for swap in swaps], indent=4))
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
@ -89,11 +90,19 @@ def _build_swap(
|
|||||||
child_traces: List[ClassifiedTrace],
|
child_traces: List[ClassifiedTrace],
|
||||||
) -> Optional[Swap]:
|
) -> Optional[Swap]:
|
||||||
if trace.abi_name == "UniswapV2Pair":
|
if trace.abi_name == "UniswapV2Pair":
|
||||||
|
return _parse_uniswap_v2_swap(trace, prior_transfers, child_traces)
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_uniswap_v2_swap(
|
||||||
|
trace: ClassifiedTrace,
|
||||||
|
prior_transfers: List[Transfer],
|
||||||
|
child_traces: List[ClassifiedTrace],
|
||||||
|
) -> Optional[Swap]:
|
||||||
pool_address = trace.to_address
|
pool_address = trace.to_address
|
||||||
transfers_to_pool = [
|
transfers_to_pool = [
|
||||||
transfer
|
transfer for transfer in prior_transfers if transfer.to_address == pool_address
|
||||||
for transfer in prior_transfers
|
|
||||||
if transfer.to_address == pool_address
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# expecting a prior transfer to the pool
|
# expecting a prior transfer to the pool
|
||||||
@ -124,8 +133,6 @@ def _build_swap(
|
|||||||
token_out_amount=pool_internal_transfer.amount,
|
token_out_amount=pool_internal_transfer.amount,
|
||||||
)
|
)
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def _get_child_traces(
|
def _get_child_traces(
|
||||||
parent_trace_address: List[int],
|
parent_trace_address: List[int],
|
||||||
@ -170,6 +177,6 @@ def _as_transfer(trace: ClassifiedTrace) -> Transfer:
|
|||||||
return Transfer(
|
return Transfer(
|
||||||
amount=trace.inputs["amount"],
|
amount=trace.inputs["amount"],
|
||||||
to_address=trace.inputs["recipient"],
|
to_address=trace.inputs["recipient"],
|
||||||
from_address=trace.from_address,
|
from_address=trace.inputs.get("sender", trace.from_address),
|
||||||
token_address=trace.to_address,
|
token_address=trace.to_address,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user