This directory now contains comprehensive refactoring analysis and action plans for the Fireblocks Raw Client codebase.
Quick reference guide (2-minute read)
- Key findings at a glance
- Identified bugs
- Priority ranking of issues
- Impact estimates
- Recommended starting point
Complete technical analysis (30+ minute read)
- Detailed code pattern analysis
- All duplicate code locations
- Magic numbers catalog
- Missing type definitions breakdown
- Complex function decomposition suggestions
- Error handling audit
- 15 specific refactoring recommendations
- Phase-based implementation plan
- Critical bugs with code examples
Practical implementation guide (20-minute read)
- 3 concrete refactoring examples with code
- Step-by-step implementation instructions
- Before/after code comparisons
- Testing checklist
- Rollback strategy
- Expected results and metrics
- 200+ lines of duplicate code across 6+ locations
- 40+ magic numbers with unclear purpose
- 13+ functions missing type annotations
- 6 major patterns repeated throughout codebase
- 5 critical bugs identified
- Phase 1 (Week 1): 8-10 hours - Highest impact, lowest effort
- Phase 2 (Week 2-3): 16-20 hours - Medium impact
- Phase 3 (Week 4+): 11-15 hours - Quality enhancements
- Total: 35-50 hours
- Extract
TransactionPollerutility (2-3 hours, fixes 6 files) - Create constants file (2-3 hours, eliminates 40+ magic numbers)
- Remove duplicate balance checker (1-2 hours, eliminates 41 lines)
- Fix critical bugs in bitcoin_raw_signer.ts (1 hour)
- Start with REFACTORING_SUMMARY.md (2 min)
- Look at "Critical Bugs" section (5 min)
- Check "Recommended Starting Point" (2 min)
- Read REFACTORING_QUICK_START.md first (20 min)
- Then consult REFACTORING_ANALYSIS.md for details (30 min)
- Reference CLAUDE.md for project context (10 min)
- Read REFACTORING_ANALYSIS.md - Section 1-6 (30 min)
- Review critical bugs (Section 11)
- Check Phase 1 recommendations (Section 7)
- Implement using QUICK_START.md examples
bitcoin_raw_signer.ts:90- Undefined variabletxIdconsolidate_unsupported_assets_with_raw_transactions.ts:251,348- Wrong escape sequencestransfer.ts:95- Too restrictive amount validationtransfer.ts:85,97- Throws strings instead of Error objectsconsolidate_unsupported_assets_with_raw_transactions.ts:253- Logic error in threshold check
1. Fix undefined variable bug (1 hour)
2. Create TransactionPoller (2-3 hours)
3. Create constants.ts (2-3 hours)
4. Create types.ts (2-3 hours)
5. Update 6 files to use TransactionPoller (3-4 hours)
6. Remove duplicate balance checker (1-2 hours)
7. Extract CLI argument parser (1-2 hours)
8. Add return types to functions (2-3 hours)
9. Extract ERC20 transfer handler (2-3 hours)
10. Refactor initWeb3Instance() (4-5 hours)
11. Create error handling utilities (2-3 hours)
-
consolidate_unsupported_assets_with_raw_transactions.ts (404 lines)
- Longest file, most complex, duplicate code
- 6-8 hours to refactor
-
web3_instance.ts (200 lines)
- Complex init function, missing types
- 5-6 hours to refactor
-
transfer.ts (274 lines)
- Duplicate handlers, missing types
- 4-5 hours to refactor
-
search_addresses_with_min_balances_from_csv.ts & gas_addresses_with_min_balances_from_csv.ts
- 100% duplicate code
- 1-2 hours to consolidate
-
deposit_gas_to_many_specified_tokens_and_chains.ts (98 lines)
- Hardcoded values, duplicated polling
- 3-4 hours to refactor
-
bitcoin_raw_signer.ts (116 lines)
- Undefined variable bug, missing types
- 3-4 hours to refactor
These can be done immediately with low risk:
- Fix undefined variable in bitcoin_raw_signer.ts
- Extract color codes to constants
- Extract gas-related constants (21000, 1.2, 1000)
- Create types for function signatures
- Extract RPC endpoint strings to constants
- Reduce duplicate code: 200+ lines → 5 lines (97% reduction)
- Reduce magic numbers: 40+ → 2 (95% reduction)
- Type coverage: 30% → 100%
- Average function length: 35 lines → 20 lines
- Error handling coverage: 40% → 95%
- IDE autocomplete works properly with types
- New contributors understand patterns easily
- Changes to shared logic happen in one place
- Tests become much easier to write
- Code is self-documenting with types
- CLAUDE.md - Project context and guidelines for AI assistants
- README.md - Original project documentation
- package.json - Dependencies and project metadata
Read: REFACTORING_SUMMARY.md
Read: REFACTORING_SUMMARY.md + REFACTORING_QUICK_START.md
Read all three documents and start implementing Phase 1
- Read REFACTORING_QUICK_START.md carefully
- Create a new branch for refactoring
- Start with TransactionPoller example
- Test thoroughly before moving to next file
- Commit after each logical change
- Where is this pattern used? See REFACTORING_ANALYSIS.md Section 1
- How much code is duplicated? See REFACTORING_ANALYSIS.md Section 2
- What should I refactor first? See REFACTORING_QUICK_START.md
- What are the critical bugs? See REFACTORING_ANALYSIS.md Section 11
- How long will this take? See impact estimates by file
- Will this break anything? See testing checklist in QUICK_START.md
- Analysis Date: 2025-11-19
- Codebase Size: 3,500+ lines across 18 TypeScript files
- Files Analyzed:
- EVM: 16 files
- Bitcoin: 2 files
- Code Generation: 3 files
- Read REFACTORING_SUMMARY.md (2 min)
- Review critical bugs section (5 min)
- Open REFACTORING_QUICK_START.md (implement after)
- Create feature branch for refactoring
- Start with TransactionPoller example
- Test each change before moving to next
Good luck with the refactoring! These improvements will significantly enhance code maintainability and reduce technical debt.