- ERC20 Transfer Handler: 100% duplicate between
transfer.tsandconsolidate_unsupported_assets_with_raw_transactions.ts - Balance Checker Classes: Identical code in
search_addresses_with_min_balances_from_csv.tsandgas_addresses_with_min_balances_from_csv.ts - Transaction Polling Logic: Repeated in 6+ files with minor variations
- Config Initialization: Identical pattern in 15+ files
- Transaction Polling (6 files, 20-30 lines each)
- CLI Argument Parsing (5 files)
- Fireblocks Client Init (15+ files)
- Transaction Status Checks (Multiple files)
- Error Handling & Logging (Inconsistent patterns)
- CSV Processing (5+ files)
Most Common:
21000- Gas limit (2 places)1.2- Gas buffer multiplier (2 places)1000- Polling interval ms (6+ places)0.0005,0.0001,0.0009- Min balance thresholds10- Amount validation threshold (unclear purpose)
- Untyped Parameters: 13+ functions
- Missing Return Types: 5+ functions
- Untyped Objects: Multiple locations
- Inconsistent Approaches: Mix of TypeScript and JSDoc
| Function | File | Lines | Complexity |
|---|---|---|---|
initWeb3Instance() |
web3_instance.ts |
185 | CRITICAL |
consolidate_unsupported_assets... |
Main file | 404 | CRITICAL |
transfer() |
transfer.ts |
274 | HIGH |
handleErc20Transfer() |
consolidate... |
107 | HIGH |
getTokenAndNativeBalance() |
consolidate... |
75 | MEDIUM |
- Undefined Variable -
bitcoin_raw_signer.ts:90-txIdis undefined - Logic Error -
consolidate...ts:253- Confused threshold check - Too Restrictive -
transfer.ts:95- Blocks legitimate >10 ETH transfers - Wrong Error Type -
transfer.ts:85,97- Throws strings not Error objects - Escape Sequence -
consolidate...ts:251,348- Double backslash breaks colors
- Missing try-catch: 5+ critical locations
- Silent failures:
estimate_tx_fees_for_all_chains.ts - Poor error messages: Generic descriptions without context
- Unhandled rejections: CSV loops without error handling
- Missing null checks: Multiple unsafe array/object access
- Extract Transaction Poller utility
- Create Constants file (magic numbers)
- Remove duplicate Balance Checker classes
- Extract CLI Argument Parser
- Add return types to public functions
- Add parameter type annotations
- Extract ERC20 Transfer Handler
- Refactor
initWeb3Instance() - Create Error Handling utilities
- Implement CSV Processor
- Create logging framework
- Add configuration system
- Input validation layer
- Testing setup
| Metric | Current | After Phase 1 | After Phase 2 | After Phase 3 |
|---|---|---|---|---|
| Total Lines | 3,500+ | 3,200 | 2,800 | 2,400 |
| Duplicate Lines | 200+ | 50 | 10 | 5 |
| Type Coverage | ~30% | ~30% | ~95% | ~100% |
| Magic Numbers | 40+ | 5 | 5 | 2 |
| Avg Function Length | 35 lines | 32 lines | 25 lines | 20 lines |
| Error Handling | 40% | 55% | 75% | 95% |
-
consolidate_unsupported_assets_with_raw_transactions.ts (404 lines)
- Longest, most complex, duplicated code
- Time: 6-8 hours
-
web3_instance.ts (200 lines)
- Complex init function, missing types, tight coupling
- Time: 5-6 hours
-
transfer.ts (274 lines)
- Duplicated handlers, missing types
- Time: 4-5 hours
-
Duplicate Balance Checker Files (46 lines each)
- 100% identical code
- Time: 1-2 hours
-
deposit_gas_to_many_specified_tokens_and_chains.ts (98 lines)
- Duplicated polling, hardcoded values
- Time: 3-4 hours
-
bitcoin_raw_signer.ts (116 lines)
- Undefined variable bug, missing types
- Time: 3-4 hours
Phase 1: 8-10 hours (biggest impact per hour) Phase 2: 16-20 hours (medium impact per hour) Phase 3: 11-15 hours (quality improvements)
Total: 35-50 hours
- Fix undefined variable in
bitcoin_raw_signer.ts:90 - Extract color codes to constants
- Create CLI parser utility
- Remove duplicate balance checker class
- Extract gas calculation constants
First Task: Extract TransactionPoller class
- Used in 6 files
- Removes 100+ lines of duplicate code
- Creates reusable utility
- High visibility of improvement
- 2-3 hours work
For detailed analysis, see REFACTORING_ANALYSIS.md