Skip to content

Add batch winnings claiming entrypoint following the place_bets batch pattern #584

@greatest0fallt1me

Description

@greatest0fallt1me

Description

The contract supports batching bets through BetManager::place_bets (contracts/predictify-hybrid/src/bets.rs:329, accepting Vec<(Symbol, String, i128)>), but there is no equivalent for claiming. Users with positions across several resolved markets must call the single-market claim_winnings entrypoint (contracts/predictify-hybrid/src/lib.rs:1697) once per market, paying repeated transaction overhead. This issue adds a claim_winnings_batch entrypoint mirroring the existing batch ergonomics.

Requirements and context

  • Model the public API on place_bets (bets.rs:329) and the existing MAX_BATCH_SIZE cap (50) used there.
  • Reuse the resolved single-claim core (see the related batch_claim completion work) so that AlreadyClaimed, MarketNotResolved, and the dispute-window check (market.dispute_window_seconds) are enforced per market.
  • The entrypoint should accept user: Address plus a Vec<Symbol> of market IDs and return a per-market result (success amount or error code), not abort on the first failure.
  • Non-functional: a single user.require_auth() should authorize the whole batch; gas cost must scale linearly and respect the existing MAX_BATCH_SIZE bound to avoid unbounded loops.
  • Emit the same per-claim events the single path emits so off-chain indexers stay consistent.

Acceptance criteria

  • A new claim_winnings_batch entrypoint exists in contracts/predictify-hybrid/src/lib.rs and is exported in the contract client.
  • Batch size is bounded (reuse MAX_BATCH_SIZE); exceeding it returns Error::InvalidInput.
  • Per-market failures (already claimed, not resolved, inside dispute window) are reported without reverting successful claims, or the chosen atomicity policy is documented explicitly.
  • Idempotency holds: re-running the batch does not double-pay.
  • Tests cover multi-market success, partial failure, and oversized-batch rejection.
  • cargo fmt, cargo clippy, and cargo test pass.

Suggested execution

1. Fork the repo and create a branchgit checkout -b feature/claim-winnings-batch.
2. Implement changes — add the entrypoint to contracts/predictify-hybrid/src/lib.rs; share the claim core with contracts/predictify-hybrid/src/bets.rs.
3. Write/extend tests — add a dedicated test module (e.g. contracts/predictify-hybrid/src/bet_tests.rs or a new file) using Soroban testutils.
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

feat: add claim_winnings_batch entrypoint mirroring place_bets batching

Guidelines

≥90% coverage on the new entrypoint and its failure branches. Document the atomicity policy in doc-comments and add the entrypoint to API_DOCUMENTATION.md (Balance Management). Timeframe: 96 hours.

Metadata

Metadata

Assignees

No one assigned

    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