Skip to content

[Contract]- Optional entry fee per participant #970

@grantfox-oss

Description

@grantfox-oss

prediction::join_event (src/prediction.rs) is currently free. Many
prediction-campaign formats let the creator charge a small entry fee that gets
pooled into the prize money, on top of whatever the creator seeded.

Goal

Let creators set an optional entry_fee. If non-zero, joining costs that much
XLM, and the fee is added to event.prize_pool.

Requirements

  1. Event struct gains:

    pub entry_fee: i128, // 0 = free to join (default)
  2. event::create_event gains entry_fee: i128 param. New EventError
    variant InvalidEntryFee = 19 if entry_fee < 0.

  3. prediction::join_event changes:

    • If event.entry_fee > 0:
      • Check TokenHelper::has_sufficient_balance(env, &xlm_token, &user, event.entry_fee),
        else return new PredictionError::InsufficientEntryFeeBalance = 14
      • Transfer entry_fee from user to env.current_contract_address() (escrow)
      • event.prize_pool = event.prize_pool.checked_add(entry_fee).ok_or(PredictionError::Overflow)?
    • Persist the updated event (prize_pool change).
    • Emit (Symbol("event"), Symbol("joined")) with
      (event_id, user, entry_fee_paid).
  4. Important for Issue 6: finalize_event must read event.prize_pool at
    finalize time (which now reflects creator seed + all collected entry fees),
    not a value cached at creation. If Issue 6 lands first, file a quick
    follow-up to confirm it already reads the live field (it should, since both
    issues operate on the same Event.prize_pool field).

Acceptance criteria

  • entry_fee == 0 → joining behaves exactly as before (free)
  • entry_fee > 0 → joining charges the user and grows event.prize_pool
  • Insufficient balance is rejected before any state change
  • get_event_prize_pool (Issue 5) reflects accumulated entry fees

Testing checklist (tests/prediction_tests.rs)

  • test_join_event_free_when_entry_fee_zero
  • test_join_event_with_entry_fee_charges_user_and_grows_pool
  • test_join_event_insufficient_balance_for_entry_fee_rejected
  • test_prize_pool_reflects_creator_seed_plus_entry_fees — N users join a
    paid event, assert get_event_prize_pool == seed + N * entry_fee

Metadata

Metadata

Assignees

Labels

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