Adding tests for CRV-WETH JIT & get_net_transfers()
This commit is contained in:
parent
49dc359f5e
commit
293c59d7c6
1
tests/blocks/14621812.json
Normal file
1
tests/blocks/14621812.json
Normal file
File diff suppressed because one or more lines are too long
@ -8,16 +8,12 @@ from mev_inspect.swaps import get_swaps
|
|||||||
from .utils import load_test_block
|
from .utils import load_test_block
|
||||||
|
|
||||||
|
|
||||||
def test_single_sandwich_jit_liquidity(trace_classifier: TraceClassifier):
|
def test_single_sandwich_jit_liquidity_WETH_USDC(trace_classifier: TraceClassifier):
|
||||||
print("\n")
|
|
||||||
test_block = load_test_block(13601096)
|
test_block = load_test_block(13601096)
|
||||||
|
|
||||||
classified_traces = trace_classifier.classify(test_block.traces)
|
classified_traces = trace_classifier.classify(test_block.traces)
|
||||||
swaps = get_swaps(classified_traces)
|
swaps = get_swaps(classified_traces)
|
||||||
jit_liquidity_instances = get_jit_liquidity(classified_traces, swaps)
|
jit_liquidity_instances = get_jit_liquidity(classified_traces, swaps)
|
||||||
|
|
||||||
# Assert Section
|
|
||||||
|
|
||||||
jit_swap = Swap( # Double check these values
|
jit_swap = Swap( # Double check these values
|
||||||
abi_name="UniswapV3Pool",
|
abi_name="UniswapV3Pool",
|
||||||
transaction_hash="0x943131400defa5db902b1df4ab5108b58527e525da3d507bd6e6465d88fa079c".lower(),
|
transaction_hash="0x943131400defa5db902b1df4ab5108b58527e525da3d507bd6e6465d88fa079c".lower(),
|
||||||
@ -25,7 +21,7 @@ def test_single_sandwich_jit_liquidity(trace_classifier: TraceClassifier):
|
|||||||
block_number=13601096,
|
block_number=13601096,
|
||||||
trace_address=[7, 0, 12, 1, 0],
|
trace_address=[7, 0, 12, 1, 0],
|
||||||
contract_address="0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8".lower(),
|
contract_address="0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8".lower(),
|
||||||
from_address="0xE592427A0AEce92De3Edee1F18E0157C05861564".lower(),
|
from_address="0xAa6E8127831c9DE45ae56bB1b0d4D4Da6e5665BD".lower(),
|
||||||
to_address="0xAa6E8127831c9DE45ae56bB1b0d4D4Da6e5665BD".lower(),
|
to_address="0xAa6E8127831c9DE45ae56bB1b0d4D4Da6e5665BD".lower(),
|
||||||
token_in_address="0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48".lower(), # USDC Contract
|
token_in_address="0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48".lower(), # USDC Contract
|
||||||
token_in_amount=1896817745609,
|
token_in_amount=1896817745609,
|
||||||
@ -43,8 +39,8 @@ def test_single_sandwich_jit_liquidity(trace_classifier: TraceClassifier):
|
|||||||
burn_transaction_hash="0x12b3d1f0e29d9093d8f3c7cce2da95edbef01aaab3794237f263da85c37c7d27".lower(),
|
burn_transaction_hash="0x12b3d1f0e29d9093d8f3c7cce2da95edbef01aaab3794237f263da85c37c7d27".lower(),
|
||||||
burn_trace=[0, 1, 0],
|
burn_trace=[0, 1, 0],
|
||||||
swaps=[jit_swap],
|
swaps=[jit_swap],
|
||||||
token0_address="0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
token0_address="0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48".lower(),
|
||||||
token1_address="0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
token1_address="0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2".lower(),
|
||||||
mint_token0_amount=10864608891029,
|
mint_token0_amount=10864608891029,
|
||||||
mint_token1_amount=8281712219747858010668,
|
mint_token1_amount=8281712219747858010668,
|
||||||
burn_token0_amount=12634177387879,
|
burn_token0_amount=12634177387879,
|
||||||
@ -54,48 +50,49 @@ def test_single_sandwich_jit_liquidity(trace_classifier: TraceClassifier):
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
# Might be super janky but this could be done with assert jit_liquidity_instances == expected_jit_liquidity
|
assert expected_jit_liquidity == jit_liquidity_instances
|
||||||
assert len(jit_liquidity_instances) == 1
|
|
||||||
assert len(jit_liquidity_instances[0].swaps) == 1
|
|
||||||
assert (
|
|
||||||
jit_liquidity_instances[0].burn_transaction_hash
|
|
||||||
== expected_jit_liquidity[0].burn_transaction_hash
|
|
||||||
)
|
|
||||||
assert (
|
|
||||||
jit_liquidity_instances[0].mint_transaction_hash
|
|
||||||
== expected_jit_liquidity[0].mint_transaction_hash
|
|
||||||
)
|
|
||||||
assert (
|
|
||||||
jit_liquidity_instances[0].burn_token0_amount
|
|
||||||
== expected_jit_liquidity[0].burn_token0_amount
|
|
||||||
)
|
|
||||||
assert (
|
|
||||||
jit_liquidity_instances[0].burn_token1_amount
|
|
||||||
== expected_jit_liquidity[0].burn_token1_amount
|
|
||||||
)
|
|
||||||
assert (
|
|
||||||
jit_liquidity_instances[0].mint_token0_amount
|
|
||||||
== expected_jit_liquidity[0].mint_token0_amount
|
|
||||||
)
|
|
||||||
assert (
|
|
||||||
jit_liquidity_instances[0].mint_token1_amount
|
|
||||||
== expected_jit_liquidity[0].mint_token1_amount
|
|
||||||
)
|
|
||||||
assert (
|
|
||||||
jit_liquidity_instances[0].bot_address == expected_jit_liquidity[0].bot_address
|
|
||||||
)
|
|
||||||
assert (
|
|
||||||
jit_liquidity_instances[0].token0_swap_volume
|
|
||||||
== expected_jit_liquidity[0].token0_swap_volume
|
|
||||||
)
|
|
||||||
assert (
|
|
||||||
jit_liquidity_instances[0].token1_swap_volume
|
|
||||||
== expected_jit_liquidity[0].token1_swap_volume
|
|
||||||
)
|
|
||||||
|
|
||||||
# Swap Checks
|
|
||||||
assert (
|
def test_single_sandwich_jit_liquidity_CRV_WETH(trace_classifier: TraceClassifier):
|
||||||
jit_liquidity_instances[0].swaps[0].transaction_hash
|
test_block = load_test_block(14621812)
|
||||||
== jit_swap.transaction_hash
|
classified_traces = trace_classifier.classify(test_block.traces)
|
||||||
|
swaps = get_swaps(classified_traces)
|
||||||
|
jit_liquidity_instances = get_jit_liquidity(classified_traces, swaps)
|
||||||
|
|
||||||
|
jit_swap = Swap( # Double check these values
|
||||||
|
abi_name="UniswapV3Pool",
|
||||||
|
transaction_hash="0x37e84f64698fe1a4852370b4d043491d5f96078d7c69e52f973932bc15ce8617".lower(),
|
||||||
|
transaction_position=5,
|
||||||
|
block_number=14621812,
|
||||||
|
trace_address=[0, 1],
|
||||||
|
contract_address="0x4c83A7f819A5c37D64B4c5A2f8238Ea082fA1f4e".lower(),
|
||||||
|
from_address="0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45".lower(),
|
||||||
|
to_address="0x1d9d04bf507b86fea6c13a412f3bff40eeb64e96".lower(),
|
||||||
|
token_in_address="0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2".lower(), # USDC Contract
|
||||||
|
token_in_amount=6206673612383009024,
|
||||||
|
token_out_address="0xD533a949740bb3306d119CC777fa900bA034cd52".lower(),
|
||||||
|
token_out_amount=8111771836975942396605,
|
||||||
|
protocol=Protocol.uniswap_v3,
|
||||||
)
|
)
|
||||||
assert jit_liquidity_instances[0].swaps[0].trace_address == jit_swap.trace_address
|
expected_jit_liquidity = [
|
||||||
|
JITLiquidity(
|
||||||
|
block_number=14621812,
|
||||||
|
bot_address="0xa57Bd00134B2850B2a1c55860c9e9ea100fDd6CF".lower(),
|
||||||
|
pool_address="0x4c83A7f819A5c37D64B4c5A2f8238Ea082fA1f4e".lower(),
|
||||||
|
mint_transaction_hash="0xdcb5eac97a6bcade485ee3dc8be0f7d8722e6ebacb3910fb31dea30ff40e694e".lower(),
|
||||||
|
mint_trace=[0, 9, 1],
|
||||||
|
burn_transaction_hash="0x499021c4f87facfffc08d143539019d8638c924a4786de15be99567ab6026b98".lower(),
|
||||||
|
burn_trace=[0, 1, 0],
|
||||||
|
swaps=[jit_swap],
|
||||||
|
token0_address="0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2".lower(),
|
||||||
|
token1_address="0xD533a949740bb3306d119CC777fa900bA034cd52".lower(),
|
||||||
|
mint_token0_amount=324305525132652136497,
|
||||||
|
mint_token1_amount=182991368595201974557004,
|
||||||
|
burn_token0_amount=330104892856183548121,
|
||||||
|
burn_token1_amount=175411922548908668697796,
|
||||||
|
token0_swap_volume=6206673612383009024,
|
||||||
|
token1_swap_volume=0,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
assert jit_liquidity_instances == expected_jit_liquidity
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
from mev_inspect.schemas.traces import Classification, DecodedCallTrace, TraceType
|
||||||
from mev_inspect.schemas.transfers import Transfer
|
from mev_inspect.schemas.transfers import Transfer
|
||||||
from mev_inspect.transfers import remove_child_transfers_of_transfers
|
from mev_inspect.transfers import get_net_transfers, remove_child_transfers_of_transfers
|
||||||
|
|
||||||
|
|
||||||
def test_remove_child_transfers_of_transfers(get_transaction_hashes, get_addresses):
|
def test_remove_child_transfers_of_transfers(get_transaction_hashes, get_addresses):
|
||||||
@ -67,6 +68,59 @@ def test_remove_child_transfers_of_transfers(get_transaction_hashes, get_address
|
|||||||
assert _equal_ignoring_order(removed_transfers, expected_transfers)
|
assert _equal_ignoring_order(removed_transfers, expected_transfers)
|
||||||
|
|
||||||
|
|
||||||
|
def test_net_transfers_same_token(get_addresses):
|
||||||
|
|
||||||
|
alice_address, bob_address, token_address = get_addresses(3)
|
||||||
|
transfer_alice_to_bob = DecodedCallTrace(
|
||||||
|
block_number=123,
|
||||||
|
transaction_hash="net_transfer_tx_hash",
|
||||||
|
block_hash="block_hash",
|
||||||
|
transaction_position=123,
|
||||||
|
type=TraceType.call,
|
||||||
|
action={},
|
||||||
|
functionName="transfer",
|
||||||
|
abiName="UniswapV3Pool",
|
||||||
|
subtraces=123,
|
||||||
|
trace_address=[0],
|
||||||
|
classification=Classification.transfer,
|
||||||
|
function_signature="transfer(address,uint256)",
|
||||||
|
from_address=alice_address,
|
||||||
|
to_address=token_address,
|
||||||
|
inputs={"recipient": bob_address, "amount": 700},
|
||||||
|
)
|
||||||
|
transfer_bob_to_alice = DecodedCallTrace(
|
||||||
|
block_number=123,
|
||||||
|
transaction_hash="net_transfer_tx_hash",
|
||||||
|
block_hash="block_hash",
|
||||||
|
transaction_position=123,
|
||||||
|
type=TraceType.call,
|
||||||
|
action={},
|
||||||
|
functionName="transfer",
|
||||||
|
abiName="UniswapV3Pool",
|
||||||
|
subtraces=123,
|
||||||
|
trace_address=[3],
|
||||||
|
classification=Classification.transfer,
|
||||||
|
function_signature="transfer(address,uint256)",
|
||||||
|
from_address=bob_address,
|
||||||
|
to_address=token_address,
|
||||||
|
inputs={"recipient": alice_address, "amount": 200},
|
||||||
|
)
|
||||||
|
|
||||||
|
expected_transfer = Transfer(
|
||||||
|
block_number=123,
|
||||||
|
transaction_hash="net_transfer_tx_hash",
|
||||||
|
trace_address=[-1],
|
||||||
|
from_address=alice_address,
|
||||||
|
to_address=bob_address,
|
||||||
|
amount=500,
|
||||||
|
token_address=token_address,
|
||||||
|
)
|
||||||
|
|
||||||
|
net_transfer = get_net_transfers([transfer_alice_to_bob, transfer_bob_to_alice])
|
||||||
|
|
||||||
|
assert expected_transfer == net_transfer[0]
|
||||||
|
|
||||||
|
|
||||||
def _equal_ignoring_order(first_list, second_list) -> bool:
|
def _equal_ignoring_order(first_list, second_list) -> bool:
|
||||||
return all(first in second_list for first in first_list) and all(
|
return all(first in second_list for first in first_list) and all(
|
||||||
second in first_list for second in second_list
|
second in first_list for second in second_list
|
||||||
|
Loading…
x
Reference in New Issue
Block a user