Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Launchpad Architecture Refactoring #451

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft

Conversation

notJoon
Copy link
Member

@notJoon notJoon commented Dec 26, 2024

Description

This PR introduces a comprehensive refactoring of the Launchpad contract architecture, focusing on optimizing reward calculations and improving data structure efficiency. The main goals are to reduce computational overhead, enhance gas efficiency, and improve the overall maintainability of the codebase.

Key Changes

Architectural Improvements

  • Separated business logic into pure functions for better testability
  • Introduced domain-specific types for better data organization (e.g., ProjectInput, ProjectTierInfo, DepositState)
  • Improved error handling by returning errors in internal functions while maintaining panic in public interfaces
  • Implemented proper pointer handling for uint256 operations using Clone()

Code Structure

  • Split large functions into smaller, focused functions with single responsibilities
  • Maintained public function signatures for backward compatibility
  • Reduced code duplication through reusable helper functions

Major Refactored Components

Project Management (launchpad_init.gno -> launchpad.gno)

  • Added validation layer with validateProjectInput
  • Separated tier creation logic into createTier
  • Improved project creation workflow with clear steps

Reward Handling (launchpad_reward.gno -> reward.gno)

  • Separated reward validation and processing logic
  • Improved uint256 handling for calculations

Deposit Management (launchpad_deposit.gno)

  • Added DepositState for better state management
  • Separated deposit validation (validateDepositCollection)
  • Improved deposit processing with clear error handling
  • Added proper indexing management

Simplified and More Organized Types

  • Introduced new type groupings for better data organization and reduced memory footprint:
    • TimeInfo: Consolidated height and timestamp pairs
    • ProjectStats: Grouped project statistics fields
    • RefundInfo: Consolidated refund-related fields

Project Structure Improvements

  • Refactored Project struct for better maintainability:
    • Replaced individual tier fields with a map-based structure (map[uint64]Tier)
    • Introduced tiersRatios map for cleaner ratio management
    • Grouped time-related fields using TimeInfo
    • Consolidated project statistics into ProjectStats
    • Grouped refund information into RefundInfo

Benefits of New Structure

  • Reduced code duplication in time-related fields
  • Better encapsulation of related data
  • More flexible tier management through map structure
  • Improved readability and maintainability
  • Reduced potential for errors in related field updates
  • More intuitive grouping of related fields

Memory Optimization

  • Reduced struct size through better field organization
  • Improved memory locality for related fields
  • More efficient handling of optional fields

Performance Considerations

  • Maintained O(1) access for critical operations
  • Reduced memory allocations where possible
  • Optimized struct sizes and memory layout

Future Improvements

  • Additional caching strategies

@notJoon notJoon changed the title refactor: launchpad refactor: Launchpad Architecture Refactoring Jan 2, 2025
@notJoon notJoon self-assigned this Jan 2, 2025
Copy link

sonarqubecloud bot commented Jan 3, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants