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
-
Event struct gains:
pub entry_fee: i128, // 0 = free to join (default)
-
event::create_event gains entry_fee: i128 param. New EventError
variant InvalidEntryFee = 19 if entry_fee < 0.
-
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).
-
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
Testing checklist (tests/prediction_tests.rs)
prediction::join_event(src/prediction.rs) is currently free. Manyprediction-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 muchXLM, and the fee is added to
event.prize_pool.Requirements
Eventstruct gains:event::create_eventgainsentry_fee: i128param. NewEventErrorvariant
InvalidEntryFee = 19ifentry_fee < 0.prediction::join_eventchanges:event.entry_fee > 0:TokenHelper::has_sufficient_balance(env, &xlm_token, &user, event.entry_fee),else return new
PredictionError::InsufficientEntryFeeBalance = 14entry_feefromusertoenv.current_contract_address()(escrow)event.prize_pool = event.prize_pool.checked_add(entry_fee).ok_or(PredictionError::Overflow)?event(prize_pool change).(Symbol("event"), Symbol("joined"))with(event_id, user, entry_fee_paid).Important for Issue 6:
finalize_eventmust readevent.prize_poolatfinalize 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_poolfield).Acceptance criteria
entry_fee == 0→ joining behaves exactly as before (free)entry_fee > 0→ joining charges the user and growsevent.prize_poolget_event_prize_pool(Issue 5) reflects accumulated entry feesTesting checklist (
tests/prediction_tests.rs)test_join_event_free_when_entry_fee_zerotest_join_event_with_entry_fee_charges_user_and_grows_pooltest_join_event_insufficient_balance_for_entry_fee_rejectedtest_prize_pool_reflects_creator_seed_plus_entry_fees— N users join apaid event, assert
get_event_prize_pool == seed + N * entry_fee