Skip to content

Latest commit

 

History

History
144 lines (114 loc) · 4.91 KB

File metadata and controls

144 lines (114 loc) · 4.91 KB

Refactoring Analysis Summary

Key Findings

1. Duplicated Code: 200+ Lines

  • ERC20 Transfer Handler: 100% duplicate between transfer.ts and consolidate_unsupported_assets_with_raw_transactions.ts
  • Balance Checker Classes: Identical code in search_addresses_with_min_balances_from_csv.ts and gas_addresses_with_min_balances_from_csv.ts
  • Transaction Polling Logic: Repeated in 6+ files with minor variations
  • Config Initialization: Identical pattern in 15+ files

2. Repeated Patterns: 6 Major Ones

  1. Transaction Polling (6 files, 20-30 lines each)
  2. CLI Argument Parsing (5 files)
  3. Fireblocks Client Init (15+ files)
  4. Transaction Status Checks (Multiple files)
  5. Error Handling & Logging (Inconsistent patterns)
  6. CSV Processing (5+ files)

3. Magic Numbers Found: 40+

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 thresholds
  • 10 - Amount validation threshold (unclear purpose)

4. Type Definition Issues

  • Untyped Parameters: 13+ functions
  • Missing Return Types: 5+ functions
  • Untyped Objects: Multiple locations
  • Inconsistent Approaches: Mix of TypeScript and JSDoc

5. Complex Functions Needing Refactoring

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

6. Critical Bugs Identified

  1. Undefined Variable - bitcoin_raw_signer.ts:90 - txId is undefined
  2. Logic Error - consolidate...ts:253 - Confused threshold check
  3. Too Restrictive - transfer.ts:95 - Blocks legitimate >10 ETH transfers
  4. Wrong Error Type - transfer.ts:85,97 - Throws strings not Error objects
  5. Escape Sequence - consolidate...ts:251,348 - Double backslash breaks colors

7. Error Handling Gaps

  • 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

Refactoring Priorities

PHASE 1: Week 1 (High Impact, Low Effort)

  • Extract Transaction Poller utility
  • Create Constants file (magic numbers)
  • Remove duplicate Balance Checker classes
  • Extract CLI Argument Parser
  • Add return types to public functions

PHASE 2: Week 2-3 (Medium Impact, Medium Effort)

  • Add parameter type annotations
  • Extract ERC20 Transfer Handler
  • Refactor initWeb3Instance()
  • Create Error Handling utilities
  • Implement CSV Processor

PHASE 3: Week 4+ (Lower Priority)

  • Create logging framework
  • Add configuration system
  • Input validation layer
  • Testing setup

Impact Estimates

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%

Files with Highest Priority

🔴 CRITICAL

  1. consolidate_unsupported_assets_with_raw_transactions.ts (404 lines)

    • Longest, most complex, duplicated code
    • Time: 6-8 hours
  2. web3_instance.ts (200 lines)

    • Complex init function, missing types, tight coupling
    • Time: 5-6 hours
  3. transfer.ts (274 lines)

    • Duplicated handlers, missing types
    • Time: 4-5 hours

🟠 HIGH

  1. Duplicate Balance Checker Files (46 lines each)

    • 100% identical code
    • Time: 1-2 hours
  2. deposit_gas_to_many_specified_tokens_and_chains.ts (98 lines)

    • Duplicated polling, hardcoded values
    • Time: 3-4 hours
  3. bitcoin_raw_signer.ts (116 lines)

    • Undefined variable bug, missing types
    • Time: 3-4 hours

Total Estimated Effort

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

Quick Wins (1-2 hours each)

  1. Fix undefined variable in bitcoin_raw_signer.ts:90
  2. Extract color codes to constants
  3. Create CLI parser utility
  4. Remove duplicate balance checker class
  5. Extract gas calculation constants

Recommended Starting Point

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