UNPKG

eip7702-delegation-tracker

Version:

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

144 lines (119 loc) 4.93 kB
/** * Debug CLI Scanner * * This script helps debug why the CLI might miss delegations */ const { EIP7702Scanner } = require('../lib/scanner'); // Test with the same network/endpoints as the main app const NETWORK = 'bsc'; // or 'arbitrum', 'base' const RPC_URL = 'https://bnb-mainnet.g.alchemy.com/v2/YOUR_API_KEY'; const WS_URL = 'wss://bnb-mainnet.g.alchemy.com/v2/YOUR_API_KEY'; async function debugScanner() { console.log('🔍 CLI SCANNER DEBUG MODE'); console.log('═══════════════════════════════════════════════════════════'); console.log(`Network: ${NETWORK}`); console.log(`RPC: ${RPC_URL}`); console.log(`WS: ${WS_URL}`); console.log('═══════════════════════════════════════════════════════════\n'); const scanner = new EIP7702Scanner(NETWORK, RPC_URL, WS_URL); // First, check if we can connect and get blocks try { const blockNumber = await scanner.provider.getBlockNumber(); console.log(`✅ Connected to ${NETWORK}, current block: ${blockNumber}\n`); } catch (error) { console.error(`❌ Failed to connect: ${error.message}`); return; } // Test scanning a recent block console.log('Testing block scanning...'); try { const currentBlock = await scanner.provider.getBlockNumber(); // Scan last 10 blocks for any transactions for (let i = 0; i < 10; i++) { const blockNum = currentBlock - i; const block = await scanner.provider.getBlock(blockNum, true); if (!block) { console.log(`Block ${blockNum}: Could not fetch`); continue; } console.log(`Block ${blockNum}: ${block.transactions.length} transactions`); // Check for type 4 transactions let type4Count = 0; let authListCount = 0; for (const tx of block.transactions) { // Debug: log transaction types const txType = typeof tx.type === 'string' ? parseInt(tx.type, 16) : tx.type; if (txType === 4) { type4Count++; console.log(` Found type 4 TX: ${tx.hash}`); console.log(` Raw type value: ${tx.type} (${typeof tx.type})`); console.log(` Has authorizationList: ${!!tx.authorizationList}`); console.log(` Has authorization_list: ${!!tx.authorization_list}`); if (tx.authorizationList || tx.authorization_list) { authListCount++; const authList = tx.authorizationList || tx.authorization_list; console.log(` ✅ Authorization list length: ${authList.length}`); console.log(` Delegated to: ${authList[0]?.address}`); } } } if (type4Count > 0) { console.log(` Summary: ${type4Count} type-4 TXs, ${authListCount} with auth lists`); } } } catch (error) { console.error('Error scanning blocks:', error); } // Now test real-time monitoring console.log('\n\nStarting real-time monitoring...\n'); let eventsReceived = 0; scanner.on('delegation', (delegation) => { eventsReceived++; console.log('✅ DELEGATION EVENT RECEIVED!'); console.log(` Event #${eventsReceived}`); console.log(` TX: ${delegation.txHash}`); console.log(` Authority: ${delegation.authority}`); console.log(` Delegated to: ${delegation.delegatedTo}`); console.log(` Block: ${delegation.blockNumber}`); }); // Also monitor raw block events const provider = scanner.wsProvider || scanner.provider; provider.on('block', async (blockNumber) => { console.log(`📦 New block: ${blockNumber}`); // Manually check this block try { const block = await scanner.provider.getBlock(blockNumber, true); if (block) { let type4Count = 0; for (const tx of block.transactions) { const txType = typeof tx.type === 'string' ? parseInt(tx.type, 16) : tx.type; if (txType === 4) { type4Count++; } } if (type4Count > 0) { console.log(` ⚡ Block contains ${type4Count} type-4 transactions!`); } } } catch (error) { console.error(` Error checking block: ${error.message}`); } }); scanner.on('error', (error) => { console.error('❌ Scanner error:', error); }); // Start watching await scanner.watchBlocks(); // Status check setInterval(() => { console.log(`⏰ [${new Date().toLocaleTimeString()}] Events received: ${eventsReceived}`); }, 30000); // Keep running process.stdin.resume(); process.on('SIGINT', () => { console.log('\nStopping...'); scanner.stop(); process.exit(0); }); } debugScanner().catch(console.error);