Merge pull request #114 from flashbots/ETHTransferLiquidations
Add support for ETH-Transfer liquidations
This commit is contained in:
commit
a1b001b2cf
@ -6,6 +6,7 @@ from mev_inspect.traces import (
|
|||||||
)
|
)
|
||||||
from mev_inspect.schemas.traces import (
|
from mev_inspect.schemas.traces import (
|
||||||
ClassifiedTrace,
|
ClassifiedTrace,
|
||||||
|
CallTrace,
|
||||||
DecodedCallTrace,
|
DecodedCallTrace,
|
||||||
Classification,
|
Classification,
|
||||||
Protocol,
|
Protocol,
|
||||||
@ -77,6 +78,7 @@ def get_aave_liquidations(
|
|||||||
block_number=trace.block_number,
|
block_number=trace.block_number,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return liquidations
|
return liquidations
|
||||||
|
|
||||||
|
|
||||||
@ -88,17 +90,17 @@ def _get_payback_token_and_amount(
|
|||||||
|
|
||||||
for child in child_traces:
|
for child in child_traces:
|
||||||
|
|
||||||
if child.classification == Classification.transfer and isinstance(
|
if isinstance(child, CallTrace):
|
||||||
child, DecodedCallTrace
|
|
||||||
):
|
|
||||||
|
|
||||||
child_transfer: Optional[Transfer] = get_transfer(child)
|
child_transfer: Optional[Transfer] = get_transfer(child)
|
||||||
|
|
||||||
if (
|
if child_transfer is not None:
|
||||||
child_transfer is not None
|
|
||||||
and child_transfer.to_address == liquidator
|
if (
|
||||||
and child.from_address in AAVE_CONTRACT_ADDRESSES
|
child_transfer.to_address == liquidator
|
||||||
):
|
and child.from_address in AAVE_CONTRACT_ADDRESSES
|
||||||
return child_transfer.token_address, child_transfer.amount
|
):
|
||||||
|
|
||||||
|
return child_transfer.token_address, child_transfer.amount
|
||||||
|
|
||||||
return liquidation.inputs["_collateral"], 0
|
return liquidation.inputs["_collateral"], 0
|
||||||
|
@ -3,7 +3,7 @@ from typing import List
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
ETH_TOKEN_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
|
ETH_TOKEN_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
|
||||||
|
|
||||||
|
|
||||||
class Transfer(BaseModel):
|
class Transfer(BaseModel):
|
||||||
|
1
tests/blocks/13302365.json
Normal file
1
tests/blocks/13302365.json
Normal file
File diff suppressed because one or more lines are too long
@ -4,6 +4,7 @@ from mev_inspect.aave_liquidations import get_aave_liquidations
|
|||||||
from mev_inspect.schemas.liquidations import Liquidation
|
from mev_inspect.schemas.liquidations import Liquidation
|
||||||
from mev_inspect.schemas.traces import Protocol
|
from mev_inspect.schemas.traces import Protocol
|
||||||
from mev_inspect.classifiers.trace import TraceClassifier
|
from mev_inspect.classifiers.trace import TraceClassifier
|
||||||
|
from mev_inspect.transfers import ETH_TOKEN_ADDRESS
|
||||||
from tests.utils import load_test_block
|
from tests.utils import load_test_block
|
||||||
|
|
||||||
|
|
||||||
@ -158,6 +159,50 @@ def test_multiple_liquidations_in_block():
|
|||||||
_assert_equal_list_of_liquidations(result, liquidations)
|
_assert_equal_list_of_liquidations(result, liquidations)
|
||||||
|
|
||||||
|
|
||||||
|
def test_liquidations_with_eth_transfer():
|
||||||
|
|
||||||
|
transaction_hash = (
|
||||||
|
"0xf687fedbc4bbc25adb3ef3a35c20c38fb7d35d86d7633d5061d2e3c4f86311b7"
|
||||||
|
)
|
||||||
|
block_number = 13302365
|
||||||
|
|
||||||
|
liquidation1 = Liquidation(
|
||||||
|
liquidated_user="0xad346c7762f74c78da86d2941c6eb546e316fbd0",
|
||||||
|
liquidator_user="0x27239549dd40e1d60f5b80b0c4196923745b1fd2",
|
||||||
|
collateral_token_address=ETH_TOKEN_ADDRESS,
|
||||||
|
debt_token_address="0x514910771af9ca656af840dff83e8264ecf986ca",
|
||||||
|
debt_purchase_amount=1809152000000000000,
|
||||||
|
received_amount=15636807387264000,
|
||||||
|
received_token_address=ETH_TOKEN_ADDRESS,
|
||||||
|
protocol=Protocol.aave,
|
||||||
|
transaction_hash=transaction_hash,
|
||||||
|
trace_address=[2, 3, 2],
|
||||||
|
block_number=block_number,
|
||||||
|
)
|
||||||
|
|
||||||
|
liquidation2 = Liquidation(
|
||||||
|
liquidated_user="0xad346c7762f74c78da86d2941c6eb546e316fbd0",
|
||||||
|
liquidator_user="0x27239549dd40e1d60f5b80b0c4196923745b1fd2",
|
||||||
|
collateral_token_address=ETH_TOKEN_ADDRESS,
|
||||||
|
debt_token_address="0x514910771af9ca656af840dff83e8264ecf986ca",
|
||||||
|
debt_purchase_amount=1809152000000000000,
|
||||||
|
received_amount=8995273139160873,
|
||||||
|
received_token_address=ETH_TOKEN_ADDRESS,
|
||||||
|
protocol=Protocol.aave,
|
||||||
|
transaction_hash=transaction_hash,
|
||||||
|
trace_address=[2, 4, 2],
|
||||||
|
block_number=block_number,
|
||||||
|
)
|
||||||
|
|
||||||
|
block = load_test_block(block_number)
|
||||||
|
trace_classifier = TraceClassifier()
|
||||||
|
classified_traces = trace_classifier.classify(block.traces)
|
||||||
|
result = get_aave_liquidations(classified_traces)
|
||||||
|
liquidations = [liquidation1, liquidation2]
|
||||||
|
|
||||||
|
_assert_equal_list_of_liquidations(result, liquidations)
|
||||||
|
|
||||||
|
|
||||||
def _assert_equal_list_of_liquidations(
|
def _assert_equal_list_of_liquidations(
|
||||||
actual_liquidations: List[Liquidation], expected_liquidations: List[Liquidation]
|
actual_liquidations: List[Liquidation], expected_liquidations: List[Liquidation]
|
||||||
):
|
):
|
||||||
|
@ -2,6 +2,7 @@ from mev_inspect.compound_liquidations import get_compound_liquidations
|
|||||||
from mev_inspect.schemas.liquidations import Liquidation
|
from mev_inspect.schemas.liquidations import Liquidation
|
||||||
from mev_inspect.schemas.traces import Protocol
|
from mev_inspect.schemas.traces import Protocol
|
||||||
from mev_inspect.classifiers.trace import TraceClassifier
|
from mev_inspect.classifiers.trace import TraceClassifier
|
||||||
|
from mev_inspect.transfers import ETH_TOKEN_ADDRESS
|
||||||
from tests.utils import load_test_block, load_comp_markets, load_cream_markets
|
from tests.utils import load_test_block, load_comp_markets, load_cream_markets
|
||||||
|
|
||||||
comp_markets = load_comp_markets()
|
comp_markets = load_comp_markets()
|
||||||
@ -18,7 +19,7 @@ def test_c_ether_liquidations():
|
|||||||
Liquidation(
|
Liquidation(
|
||||||
liquidated_user="0xb5535a3681cf8d5431b8acfd779e2f79677ecce9",
|
liquidated_user="0xb5535a3681cf8d5431b8acfd779e2f79677ecce9",
|
||||||
liquidator_user="0xe0090ec6895c087a393f0e45f1f85098a6c33bef",
|
liquidator_user="0xe0090ec6895c087a393f0e45f1f85098a6c33bef",
|
||||||
collateral_token_address="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
collateral_token_address=ETH_TOKEN_ADDRESS,
|
||||||
debt_token_address="0x39aa39c021dfbae8fac545936693ac917d5e7563",
|
debt_token_address="0x39aa39c021dfbae8fac545936693ac917d5e7563",
|
||||||
debt_purchase_amount=268066492249420078,
|
debt_purchase_amount=268066492249420078,
|
||||||
received_amount=4747650169097,
|
received_amount=4747650169097,
|
||||||
@ -43,7 +44,7 @@ def test_c_ether_liquidations():
|
|||||||
Liquidation(
|
Liquidation(
|
||||||
liquidated_user="0x45df6f00166c3fb77dc16b9e47ff57bc6694e898",
|
liquidated_user="0x45df6f00166c3fb77dc16b9e47ff57bc6694e898",
|
||||||
liquidator_user="0xe0090ec6895c087a393f0e45f1f85098a6c33bef",
|
liquidator_user="0xe0090ec6895c087a393f0e45f1f85098a6c33bef",
|
||||||
collateral_token_address="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
collateral_token_address=ETH_TOKEN_ADDRESS,
|
||||||
debt_token_address="0x35a18000230da775cac24873d00ff85bccded550",
|
debt_token_address="0x35a18000230da775cac24873d00ff85bccded550",
|
||||||
debt_purchase_amount=414547860568297082,
|
debt_purchase_amount=414547860568297082,
|
||||||
received_amount=321973320649,
|
received_amount=321973320649,
|
||||||
@ -69,7 +70,7 @@ def test_c_ether_liquidations():
|
|||||||
Liquidation(
|
Liquidation(
|
||||||
liquidated_user="0xacbcf5d2970eef25f02a27e9d9cd31027b058b9b",
|
liquidated_user="0xacbcf5d2970eef25f02a27e9d9cd31027b058b9b",
|
||||||
liquidator_user="0xe0090ec6895c087a393f0e45f1f85098a6c33bef",
|
liquidator_user="0xe0090ec6895c087a393f0e45f1f85098a6c33bef",
|
||||||
collateral_token_address="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
collateral_token_address=ETH_TOKEN_ADDRESS,
|
||||||
debt_token_address="0x35a18000230da775cac24873d00ff85bccded550",
|
debt_token_address="0x35a18000230da775cac24873d00ff85bccded550",
|
||||||
debt_purchase_amount=1106497772527562662,
|
debt_purchase_amount=1106497772527562662,
|
||||||
received_amount=910895850496,
|
received_amount=910895850496,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user