feat: implement platform statistics and analytics tracking #237
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.
Pull Request Description
π Basic Information
Type of Change
Please select the type of change this PR introduces:
Related Issues
Closes #224
Priority Level
π Detailed Description
What does this PR do?
Implements comprehensive statistics and analytics tracking for the Predictify platform, enabling real-time insights into platform usage, user activity, and market performance. The feature provides both platform-wide and user-specific metrics through secure, gas-efficient read-only query functions with event emission for tracking changes.
Why is this change needed?
Platform analytics are essential for:
How was this tested?
Alternative Solutions Considered
ποΈ Smart Contract Specific
Contract Changes
Please check all that apply:
Contract Modules Implemented
Platform-Wide Statistics:
get_total_events() -> u64- Returns total count of events createdget_total_bets_placed() -> u64- Returns total count of bets across platformget_total_volume() -> i128- Returns total trading volume in XLM/tokensget_total_fees_collected() -> i128- Returns cumulative fees collectedget_active_events_count() -> u64- Returns count of currently active eventsUser-Specific Statistics:
get_user_total_bets(user: Address) -> u64- Returns user's total bets placedget_user_total_winnings(user: Address) -> i128- Returns user's cumulative winningsget_user_win_rate(user: Address) -> Percentage- Returns user's win rate as percentageEvents Emitted:
StatisticsUpdatedEvent- Emitted when platform statistics changeUserStatsUpdatedEvent- Emitted when user-specific statistics changeSecurity Considerations
π§ͺ Testing
Test Coverage
Manual Testing Steps
π Documentation
Documentation Updates
Files Changed
src/lib.rs- Added statistics functions and module exportssrc/statistics.rs- Complete statistics tracking logic and query functions (NEW)src/types.rs- Added Statistics struct and analytics typessrc/storage.rs- Added statistics storage managementsrc/events.rs- Added StatisticsUpdatedEvent and UserStatsUpdatedEventtests/statistics_test.rs- Comprehensive test suite (NEW)Breaking Changes
No breaking changes. This feature is additive and does not modify existing contract functionality or storage structures.
π Code Quality
Code Review Checklist
Performance Impact
Security Review
π Deployment & Integration
Deployment Notes
Integration Points
π Impact Assessment
User Impact
Business Impact
β Final Checklist
Pre-Submission
Review Readiness
π¬ Notes for Reviewers
Please pay special attention to:
Questions for reviewers:
π Additional Resources
Thank you for reviewing this contribution to Predictify! π