test(swap-detection): add automated swap detection and analysis tools
- Add auto_test_swaps.sh for monitoring live Arbitrum mainnet - Add fetch_swaps.sh for capturing recent swap transactions - Add analyze_detected_swaps.py for parsing and analyzing swap data - Add comprehensive test results documentation Test Results: - Successfully detected 91 swaps from live mainnet - Identified 33 unique liquidity pools - Validated UniswapV2 and UniswapV3 event detection - Confirmed transaction data capture accuracy Key Features: - Real-time monitoring with 3-second polling - UniswapV2/V3 swap event signature filtering - Transaction impersonation for Anvil replay (blocked by archive RPC) - Comprehensive analytics and reporting Known Limitations: - Anvil replay requires archive RPC access - WebSocket connection to Anvil not functional - Recommendation: Deploy to testnet for full E2E testing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
94
scripts/fetch_swaps.sh
Executable file
94
scripts/fetch_swaps.sh
Executable file
@@ -0,0 +1,94 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Fetch recent swaps from Arbitrum and save them for testing
|
||||
|
||||
set -e
|
||||
|
||||
CAST="/home/administrator/.foundry/bin/cast"
|
||||
ARBITRUM_RPC="https://arb1.arbitrum.io/rpc"
|
||||
OUTPUT_FILE="test_swaps.json"
|
||||
SWAP_COUNT=10
|
||||
|
||||
echo "Fetching recent swaps from Arbitrum..."
|
||||
|
||||
# Get latest block number
|
||||
LATEST_BLOCK=$($CAST block-number --rpc-url "$ARBITRUM_RPC")
|
||||
echo "Latest block: $LATEST_BLOCK"
|
||||
|
||||
# Start from 100 blocks ago
|
||||
START_BLOCK=$((LATEST_BLOCK - 100))
|
||||
|
||||
echo "Scanning blocks $START_BLOCK to $LATEST_BLOCK for swap transactions..."
|
||||
echo "[" > "$OUTPUT_FILE"
|
||||
|
||||
SWAPS_FOUND=0
|
||||
|
||||
# Known swap event signatures
|
||||
UNISWAP_V2_SWAP="0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822" # Swap(address,uint256,uint256,uint256,uint256,address)
|
||||
UNISWAP_V3_SWAP="0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67" # Swap(address,address,int256,int256,uint160,uint128,int24)
|
||||
|
||||
for ((BLOCK=START_BLOCK; BLOCK<=LATEST_BLOCK && SWAPS_FOUND<SWAP_COUNT; BLOCK++)); do
|
||||
echo "Scanning block $BLOCK..." >&2
|
||||
|
||||
# Get block with transactions
|
||||
BLOCK_DATA=$($CAST block $BLOCK --json --rpc-url "$ARBITRUM_RPC" 2>/dev/null || echo "{}")
|
||||
|
||||
# Extract transaction hashes
|
||||
TX_HASHES=$(echo "$BLOCK_DATA" | jq -r '.transactions[]?' 2>/dev/null || echo "")
|
||||
|
||||
for TX_HASH in $TX_HASHES; do
|
||||
if [ -z "$TX_HASH" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Get transaction receipt
|
||||
RECEIPT=$($CAST receipt "$TX_HASH" --json --rpc-url "$ARBITRUM_RPC" 2>/dev/null || echo "{}")
|
||||
|
||||
# Check if this transaction has swap events
|
||||
HAS_SWAP=$(echo "$RECEIPT" | jq -r ".logs[]? | select(.topics[0]? == \"$UNISWAP_V2_SWAP\" or .topics[0]? == \"$UNISWAP_V3_SWAP\") | .address" | head -1)
|
||||
|
||||
if [ ! -z "$HAS_SWAP" ]; then
|
||||
echo "Found swap in tx $TX_HASH" >&2
|
||||
|
||||
# Get full transaction
|
||||
TX_DATA=$($CAST tx "$TX_HASH" --json --rpc-url "$ARBITRUM_RPC" 2>/dev/null || echo "{}")
|
||||
|
||||
# Extract relevant fields
|
||||
TO=$(echo "$TX_DATA" | jq -r '.to')
|
||||
FROM=$(echo "$TX_DATA" | jq -r '.from')
|
||||
VALUE=$(echo "$TX_DATA" | jq -r '.value')
|
||||
INPUT=$(echo "$TX_DATA" | jq -r '.input')
|
||||
GAS=$(echo "$TX_DATA" | jq -r '.gas')
|
||||
|
||||
# Add swap to output
|
||||
if [ $SWAPS_FOUND -gt 0 ]; then
|
||||
echo "," >> "$OUTPUT_FILE"
|
||||
fi
|
||||
|
||||
cat >> "$OUTPUT_FILE" <<EOF
|
||||
{
|
||||
"txHash": "$TX_HASH",
|
||||
"block": $BLOCK,
|
||||
"from": "$FROM",
|
||||
"to": "$TO",
|
||||
"value": "$VALUE",
|
||||
"input": "$INPUT",
|
||||
"gas": "$GAS",
|
||||
"poolAddress": "$HAS_SWAP"
|
||||
}
|
||||
EOF
|
||||
|
||||
SWAPS_FOUND=$((SWAPS_FOUND + 1))
|
||||
|
||||
if [ $SWAPS_FOUND -ge $SWAP_COUNT ]; then
|
||||
break 2
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
echo "" >> "$OUTPUT_FILE"
|
||||
echo "]" >> "$OUTPUT_FILE"
|
||||
|
||||
echo "Found $SWAPS_FOUND swaps and saved to $OUTPUT_FILE"
|
||||
cat "$OUTPUT_FILE"
|
||||
Reference in New Issue
Block a user