UNPKG

eip7702-delegation-tracker

Version:

CLI tool for tracking and sweeping EIP-7702 delegation setup transactions on EVM chains

129 lines (108 loc) • 5.51 kB
/** * Debug Monitor for Arbitrum * * Shows ALL EIP-7702 delegations to help identify why specific ones might be missed */ const { EIP7702Scanner } = require('../lib/scanner'); // Configuration const TARGET_CONTRACT = '0x02d5251018c6fde7bbef8412585714fa7c1df3ac'; // The contract you're looking for const ARB_WS_URL = 'wss://arb-mainnet.g.alchemy.com/v2/YOUR_API_KEY'; const ARB_RPC_URL = 'https://arb-mainnet.g.alchemy.com/v2/YOUR_API_KEY'; async function debugMonitor() { console.log('šŸ” DEBUG MONITOR - ARBITRUM'); console.log('═══════════════════════════════════════════════════════════'); console.log(`šŸ“œ Looking for delegations to: ${TARGET_CONTRACT}`); console.log(`🌐 Network: Arbitrum (Chain ID: 42161)`); console.log(`šŸ”Œ WebSocket: ${ARB_WS_URL.substring(0, 50)}...`); console.log('═══════════════════════════════════════════════════════════\n'); // Initialize scanner with Arbitrum network const scanner = new EIP7702Scanner('arbitrum', ARB_RPC_URL, ARB_WS_URL); let totalEIP7702 = 0; let matchingDelegations = 0; const allDelegatedContracts = new Set(); // Log EVERY delegation to see what's being detected scanner.on('delegation', (delegation) => { totalEIP7702++; const delegatedTo = delegation.delegatedTo?.toLowerCase(); allDelegatedContracts.add(delegatedTo); console.log(`\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`); console.log(`⚔ EIP-7702 DELEGATION #${totalEIP7702}`); console.log(`šŸ“¦ Block: ${delegation.blockNumber}`); console.log(`šŸ“ TX: ${delegation.txHash}`); console.log(`šŸ‘¤ Authority: ${delegation.authority}`); console.log(`šŸ“œ Delegated To: ${delegatedTo}`); // Check if this matches our target if (delegatedTo === TARGET_CONTRACT.toLowerCase()) { matchingDelegations++; console.log(`āœ…āœ…āœ… MATCH FOUND! This is delegation #${matchingDelegations} to our target!`); } else { console.log(`āŒ Not our target (looking for ${TARGET_CONTRACT})`); } console.log(`\nšŸ“Š Stats: ${totalEIP7702} total EIP-7702 txs | ${matchingDelegations} matches | ${allDelegatedContracts.size} unique contracts`); console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`); }); scanner.on('error', (error) => { console.error('āŒ Scanner Error:', error.message); }); scanner.on('connected', () => { console.log('āœ… Connected to Arbitrum via Alchemy WebSocket'); console.log('šŸ‘€ Monitoring ALL EIP-7702 delegations...\n'); }); scanner.on('disconnected', () => { console.log('āš ļø Disconnected from Arbitrum WebSocket'); }); // Start watching console.log('šŸš€ Starting monitor...'); await scanner.watchBlocks(); // Also scan recent blocks to check if the delegation already happened console.log('\nšŸ“œ Scanning last 50 blocks for recent delegations...\n'); try { const currentBlock = await scanner.provider.getBlockNumber(); console.log(`Current block: ${currentBlock}`); for (let i = 0; i < 50; i++) { const blockNum = currentBlock - i; const delegations = await scanner.scanBlock(blockNum); if (delegations.length > 0) { console.log(`Block ${blockNum}: Found ${delegations.length} EIP-7702 delegation(s)`); delegations.forEach(d => { const delegatedTo = d.delegatedTo?.toLowerCase(); if (delegatedTo === TARGET_CONTRACT.toLowerCase()) { console.log(` āœ… FOUND TARGET in block ${blockNum}!`); console.log(` TX: ${d.txHash}`); console.log(` Authority: ${d.authority}`); } else { console.log(` - Delegation to: ${delegatedTo}`); } }); } } console.log('\nHistorical scan complete. Now monitoring real-time...\n'); } catch (error) { console.error('Error scanning historical blocks:', error.message); } // Status every 20 seconds setInterval(() => { console.log(`\nā° [${new Date().toLocaleTimeString()}] Status:`); console.log(` - Total EIP-7702 seen: ${totalEIP7702}`); console.log(` - Matches to ${TARGET_CONTRACT}: ${matchingDelegations}`); console.log(` - Unique contracts seen: ${allDelegatedContracts.size}`); if (allDelegatedContracts.size > 0 && allDelegatedContracts.size <= 5) { console.log(` - Contracts: ${Array.from(allDelegatedContracts).join(', ')}`); } }, 20000); // Keep running process.stdin.resume(); process.on('SIGINT', () => { console.log('\n\nšŸ“Š Final Report:'); console.log(`Total EIP-7702 delegations seen: ${totalEIP7702}`); console.log(`Matches to target contract: ${matchingDelegations}`); console.log(`All delegated contracts seen:`); Array.from(allDelegatedContracts).forEach(contract => { console.log(` - ${contract} ${contract === TARGET_CONTRACT.toLowerCase() ? 'āœ… (TARGET)' : ''}`); }); scanner.stop(); process.exit(0); }); } // Run debugMonitor().catch(console.error);