Skip to content

Add batch platform-fee collection across multiple markets in FeeManager #585

@greatest0fallt1me

Description

@greatest0fallt1me

Description

Fee collection is single-market only. FeeManager::collect_fees (contracts/predictify-hybrid/src/fees.rs:720) collects from one market_id per call, so an admin closing out many resolved markets must issue one transaction each. This issue adds a batch collection entrypoint that aggregates fees across a bounded set of markets in a single admin-authorized call, consistent with the batch pattern already used for bets.

Requirements and context

  • Build on FeeManager::collect_fees (fees.rs:720) and its guards (FeeValidator::validate_market_for_fee_collection, FeeAlreadyCollected, NoFeesToCollect).
  • Fee math must continue to use the checked helpers in fees.rs (checked_fee_add, checked_mul_div_floor) which raise Error::FeeArithmeticOverflow; the batch must not bypass these.
  • Reuse FeeTracker::record_fee_collection (fees.rs:1413) per market so analytics (get_fee_analytics) remain accurate.
  • Non-functional: bound the batch size (reuse the MAX_BATCH_SIZE/BatchConfig.max_operations_per_batch convention), authorize once via the admin, and skip-with-error markets that have already been collected rather than aborting the whole batch.
  • Emit per-market fee-collection events identical to the single path.

Acceptance criteria

  • A collect_fees_batch entrypoint accepting a bounded Vec<Symbol> exists and returns per-market collected amounts plus an aggregate total.
  • Already-collected markets surface Error::FeeAlreadyCollected for that entry without reverting successful collections.
  • All arithmetic uses the existing checked helpers; no raw i128 math is introduced.
  • Batch size is capped; exceeding the cap returns Error::InvalidInput.
  • Tests cover multi-market collection, double-collection, empty/zero-fee markets, and oversized batches.
  • cargo fmt, cargo clippy, and cargo test pass.

Suggested execution

1. Fork the repo and create a branchgit checkout -b feature/collect-fees-batch.
2. Implement changes — extend contracts/predictify-hybrid/src/fees.rs and add the entrypoint in contracts/predictify-hybrid/src/lib.rs.
3. Write/extend tests — add fee-batch cases (Soroban testutils), e.g. alongside the fee idempotency tests.
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 collect_fees_batch for multi-market fee collection

Guidelines

≥90% coverage on new branches. Add doc-comments and update API_DOCUMENTATION.md (Fee Management) and docs/contracts/FEES.md. 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