Skip to content

Replace stubbed zero-valued metrics in QueryManager balance and pool queries #589

@greatest0fallt1me

Description

@greatest0fallt1me

Description

Several read APIs return placeholder zeros. In contracts/predictify-hybrid/src/queries.rs, query_user_balance hardcodes available_balance = 0i128, total_winnings = 0i128, and resolved_market_count = 0u32 (each tagged // TODO), and query_market_pool hardcodes platform_fees = 0i128 // TODO: Retrieve from fees module. The module's own "Gap Analysis" doc-comment explicitly flags query_contract_state as having "stubbed metrics". Clients relying on these fields receive misleading data. This issue computes the real values.

Requirements and context

  • queries.rs:571 query_user_balance — populate total_winnings and resolved_market_count from the user's resolved positions (use BetManager/resolution helpers), and source available_balance from the token/balances layer (contracts/predictify-hybrid/src/balances.rs / tokens.rs).
  • queries.rs:607 query_market_pool — populate platform_fees from the fee module (FeeManager/FeeCalculator::calculate_platform_fee in fees.rs).
  • The Gap Analysis block at the top of queries.rs enumerates the stubbed/inconsistent fields and should be updated as items are resolved.
  • Non-functional: queries must stay read-only and gas-bounded; reuse the existing pagination cap MAX_PAGE_SIZE = 50 (queries.rs:56) where iteration is required, and avoid unbounded scans.
  • Keep return types (UserBalanceQuery, MarketPoolQuery) stable for client compatibility.

Acceptance criteria

  • query_user_balance returns real total_winnings and resolved_market_count; available_balance is sourced from the balances/token layer or the field is documented as wallet-side if not on-chain.
  • query_market_pool returns real platform_fees.
  • No remaining // TODO/hardcoded-zero placeholders in the touched functions.
  • The Gap Analysis doc-comment in queries.rs is updated to reflect resolved items.
  • Tests assert the computed values against known fixtures (resolved + unresolved markets).
  • cargo fmt, cargo clippy, and cargo test pass.

Suggested execution

1. Fork the repo and create a branchgit checkout -b feature/queries-real-metrics.
2. Implement changescontracts/predictify-hybrid/src/queries.rs, pulling from fees.rs, balances.rs, and resolution helpers.
3. Write/extend tests — extend contracts/predictify-hybrid/src/query_tests.rs (re-enable if needed) with fixtures.
4. Test and commit

cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test -p predictify-hybrid
stellar contract build --verbose

Example commit message

improvement: compute real balance/pool metrics in QueryManager

Guidelines

≥90% coverage on the updated queries. Update doc-comments and API_DOCUMENTATION.md (Query Functions). Timeframe: 96 hours.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GRANTFOX OSSGrantFox OSS programMAYBE REWARDEDGrantFox — potentially rewardedOFFICIAL CAMPAIGNGrantFox official campaignimprovementRefactor, performance, or tech-debtintermediateModerate complexitysmart-contractSoroban / Rust contract work

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions