refactor: centralize fee management and resolution systems into dedicated modules#131
Merged
Merged
Conversation
…ract, simplifying market finalization and oracle result fetching
…ct for enhanced market resolution and analytics
…ify Hybrid contract, including oracle and market resolution methods, validation, and analytics
…tract, covering oracle result fetching, market resolution, validation, state management, and performance metrics
…ictify Hybrid contract for enhanced type management
…tify Hybrid contract for improved type management
…r no_std compatibility and verify successful operation instead
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description
🎯 Overview
This PR refactors the Predictify Hybrid contract by centralizing fee management and resolution logic into dedicated, well-organized modules. This improves code maintainability, testability, and follows the single responsibility principle.
Closes #110
�� Changes Made
1. Fee Management System Refactor (
fees.rs)Created comprehensive fee management module with the following components:
FeeManager: Main fee collection and processing logicFeeCalculator: Dynamic fee calculation with market size adjustmentsFeeValidator: Input validation and permission checksFeeUtils: Utility functions for fee eligibility and status checksFeeConfigManager: Configuration management with defaultsFeeAnalytics: Fee statistics and performance metricsFeeTracker: Historical fee tracking and reportingKey Features:
2. Resolution System Refactor (
resolution.rs)Created dedicated resolution management module with:
OracleResolutionManager: Oracle result fetching and validationMarketResolutionManager: Final market resolution logicOracleResolutionValidator: Oracle-specific validation rulesMarketResolutionValidator: Market resolution validationOracleResolutionAnalytics: Oracle performance statisticsMarketResolutionAnalytics: Resolution method determination and confidence scoringResolutionUtils: Helper functions for state management and eligibility checksResolutionTesting: Testing utilities for resolution scenariosKey Features:
Active,OracleResolved,MarketResolved,Disputed,Finalized)3. Contract Interface Updates (
lib.rs)collect_fees(): Admin fee collection from resolved marketsget_fee_analytics(): Fee statistics and performance dataupdate_fee_config(): Admin fee configuration updatesget_fee_config(): Current fee configuration retrievalvalidate_market_fees(): Market fee validationget_oracle_resolution(): Oracle resolution data retrievalget_market_resolution(): Market resolution data retrievalvalidate_resolution(): Resolution validation with recommendationsget_resolution_state(): Current resolution statecan_resolve_market(): Market resolution eligibility checkget_resolution_analytics(): Resolution statisticsget_oracle_stats(): Oracle performance metricscalculate_resolution_time(): Resolution timing calculations4. Type System Updates
MarketResolution: Complete market resolution dataOracleResolution: Oracle resolution detailsCommunityConsensus: Community voting consensusResolutionState: Resolution state enumerationResolutionMethod: Resolution method enumerationResolutionAnalytics: Resolution statisticsResolutionValidation: Validation results with recommendationsFeeConfig: Configurable fee parametersFeeBreakdown: Detailed fee calculationsFeeAnalytics: Fee performance metricsFeeCollection: Fee collection records5. Error Handling Enhancements (
errors.rs)FeesAlreadyCollected: Prevents duplicate fee collectionInsufficientStakesForFees: Minimum stake requirementsInvalidFeeConfig: Fee configuration validationFeeCollectionDisabled: Fee system status checksResolutionNotEligible: Market resolution validationInvalidResolutionMethod: Resolution method validationResolutionAlreadyFinalized: Prevents duplicate resolution6. Comprehensive Test Suite (
test.rs)🏗️ Architecture Improvements
Modular Design
Type Safety
Performance Optimizations
�� Testing Strategy
Unit Tests
Test Utilities
📊 Impact Analysis
Positive Impacts
Risk Mitigation
🔍 Code Quality Metrics
�� Deployment Notes
Pre-deployment Checklist
Post-deployment Monitoring
📝 Future Enhancements
Planned Improvements
Technical Debt Addressed
Reviewers: Please focus on:
Testing: Run the full test suite to ensure all functionality works as expected.