Skip to content

feat: add get_pool_stats with optional odds calculation (#418)#471

Merged
Yunusabdul38 merged 2 commits intoWeb3Novalabs:mainfrom
ayomideadeniran:issue-418-pool-stats-optimization
Mar 27, 2026
Merged

feat: add get_pool_stats with optional odds calculation (#418)#471
Yunusabdul38 merged 2 commits intoWeb3Novalabs:mainfrom
ayomideadeniran:issue-418-pool-stats-optimization

Conversation

@ayomideadeniran
Copy link
Copy Markdown
Contributor

  • Add PoolStats struct with comprehensive pool statistics
  • Implement get_pool_stats(pool_id, include_odds) function
  • Optional odds calculation to optimize performance for large pools
  • Odds represented as fixed-point numbers with 4 decimal precision (e.g., 7500 = 0.75)
  • When include_odds=false, returns None to skip expensive calculation
  • When pool has no stakes, odds is None even if include_odds=true

Implementation details:

  • Avoids floating point arithmetic by using integer math with 10_000 multiplier
  • Checks overflow in odds calculation
  • Iterates through all outcomes only when include_odds=true and total_stake>0

Tests added:

  • test_get_pool_stats_without_odds: Verify basic stats without odds calculation
  • test_get_pool_stats_with_odds: Verify odds are calculated correctly with 4 decimals
  • test_get_pool_stats_empty_pool: Handle pools with no predictions
  • test_get_pool_stats_resolved_pool: Verify stats work for resolved pools

Fixes #418

…#418)

- Add PoolStats struct with comprehensive pool statistics
- Implement get_pool_stats(pool_id, include_odds) function
- Optional odds calculation to optimize performance for large pools
- Odds represented as fixed-point numbers with 4 decimal precision (e.g., 7500 = 0.75)
- When include_odds=false, returns None to skip expensive calculation
- When pool has no stakes, odds is None even if include_odds=true

Implementation details:
- Avoids floating point arithmetic by using integer math with 10_000 multiplier
- Checks overflow in odds calculation
- Iterates through all outcomes only when include_odds=true and total_stake>0

Tests added:
- test_get_pool_stats_without_odds: Verify basic stats without odds calculation
- test_get_pool_stats_with_odds: Verify odds are calculated correctly with 4 decimals
- test_get_pool_stats_empty_pool: Handle pools with no predictions
- test_get_pool_stats_resolved_pool: Verify stats work for resolved pools

Fixes Web3Novalabs#418
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

Someone is attempting to deploy a commit to the shola's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 27, 2026

@ayomideadeniran Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Yunusabdul38 Yunusabdul38 merged commit 076f014 into Web3Novalabs:main Mar 27, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize PoolStats calculation

2 participants