Refactor: Centralize Fee Management System in Predictify Hybrid Contract#130
Merged
Conversation
…rid contract, including fee collection, validation, analytics, and configuration management
…alities, including fee processing during market creation, fee collection, analytics retrieval, configuration updates, and market fee validation
…ecate old function in Predictify Hybrid contract
…ntract, covering fee collection, validation, configuration, and analytics
… implementations in VotingManager and VotingUtils
…figuration timestamp
Contributor
|
Thanks for the PR @1nonlypiece |
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.
This PR implements a comprehensive refactor of the fee management system in the
predictify-hybridcontract, moving from scattered fee logic across multiple files to a dedicated, modular fee management system.Closes #109
Changes Made
🏗️ New Fee Management Architecture
contracts/predictify-hybrid/src/fees.rs- Centralized fee management moduleFeeConfig- Configurable fee parametersFeeAnalytics- Fee collection statistics and metricsFeeBreakdown- Detailed fee calculation breakdownsFeeValidation- Fee validation results and error reporting🔧 Core Fee Management Components
FeeManager - Main fee orchestration
collect_fees()- Centralized fee collection logicprocess_creation_fee()- Market creation fee handlingget_fee_analytics()- Fee statistics and reportingupdate_fee_config()- Dynamic fee configuration updatesFeeCalculator - Fee computation engine
calculate_platform_fee()- Platform fee calculationscalculate_user_payout_after_fees()- User payout computationscalculate_fee_breakdown()- Detailed fee breakdownscalculate_dynamic_fee()- Volume-based fee adjustmentsFeeValidator - Validation and safety checks
validate_admin_permissions()- Admin authorizationvalidate_fee_amount()- Fee amount bounds checkingvalidate_market_for_fee_collection()- Market eligibility validationvalidate_fee_config()- Configuration integrity checksFeeUtils - Utility functions
can_collect_fees()- Quick eligibility checksget_fee_eligibility()- Detailed eligibility with reasonsFeeConfigManager - Configuration management
store_fee_config()- Configuration persistenceget_fee_config()- Configuration retrievalreset_to_defaults()- Default configuration restorationFeeAnalytics - Analytics and reporting
calculate_analytics()- Overall fee statisticsget_market_fee_stats()- Per-market fee metricscalculate_fee_efficiency()- Fee collection efficiency🔄 Integration Updates
Updated
lib.rsfeesmodule integrationcollect_fees()get_fee_analytics()get_fee_config()update_fee_config()validate_market_fees()Updated
markets.rsfeesmoduleUpdated
voting.rsfeesmodule🧪 Comprehensive Test Suite
test.rs🔒 Safety and Validation Features
⚙️ Configuration Management
Technical Details
Fee Configuration Parameters
platform_fee_percentage- Platform fee percentage (default: 2%)creation_fee- Market creation fee (default: 10 XLM)min_fee_amount- Minimum fee amount (default: 0.1 XLM)max_fee_amount- Maximum fee amount (default: 100 XLM)collection_threshold- Minimum stakes for fee collection (default: 10 XLM)fees_enabled- Global fee enable/disable flagDynamic Fee Adjustments
Analytics and Reporting
Benefits
✅ Modularity - Clean separation of fee concerns
✅ Maintainability - Centralized fee logic for easier updates
✅ Testability - Comprehensive test coverage for all fee operations
✅ Safety - Multiple validation layers and error handling
✅ Flexibility - Dynamic configuration and runtime updates
✅ Analytics - Detailed fee reporting and metrics
✅ Backward Compatibility - Existing functionality preserved
Testing
Breaking Changes
None - This refactor maintains full backward compatibility while adding new functionality.
Migration Notes
No migration required - existing fee collection logic continues to work as before, with enhanced capabilities available through new methods.