event::create_event (src/event.rs) only charges a flat creation_fee that
goes to the global treasury (event.rs:99-101) — this is a platform
anti-spam fee, not a prize pool. There is currently no way for a creator to
fund a prize pool or define how it's split among winners. src/token.rs has
unused helpers (collect_entry_fee, distribute_winnings,
calculate_winnings) that hint this was planned but never wired up.
Goal
Let a creator deposit an XLM prize pool when creating an event, and define what
percentage of it each leaderboard rank receives (e.g. [40, 30, 20, 5, 5] for
top 5).
Requirements
-
Event struct gains:
pub prize_pool: i128,
pub reward_distribution: Vec<u32>, // percentages, 1-based rank order, sum == 100 when prize_pool > 0
pub is_finalized: bool,
-
New constants in src/storage_types.rs:
pub const MAX_REWARD_RANKS: u32 = 5;
pub const REWARD_PERCENT_TOTAL: u32 = 100;
-
event::create_event signature gains:
prize_pool: i128,
reward_distribution: Vec<u32>,
-
New EventError variants:
InvalidPrizePool = 13 — prize_pool < 0
InvalidRewardDistribution = 14 — any of:
prize_pool > 0 and reward_distribution.is_empty()
reward_distribution.len() > MAX_REWARD_RANKS
- any entry
== 0 or > 100
sum(reward_distribution) != 100 (only enforced when prize_pool > 0;
if prize_pool == 0, reward_distribution must be empty — this is a
"fun event", no payouts)
InsufficientPrizePoolFunds = 15 — creator's XLM balance < prize_pool
-
Flow changes in create_event:
- Validate
reward_distribution as above.
- If
prize_pool > 0: transfer prize_pool from creator to
env.current_contract_address() (escrow) — this is a second,
separate transfer from the existing creation_fee → treasury transfer.
Do not conflate the two.
- Store
prize_pool, reward_distribution, is_finalized: false on Event.
- Emit
(Symbol("event"), Symbol("prize_pool_funded")) with
(event_id, prize_pool, reward_distribution).
-
New read-only views (src/views.rs + lib.rs):
pub fn get_event_prize_pool(env: Env, event_id: u64) -> i128;
pub fn get_event_reward_distribution(env: Env, event_id: u64) -> Vec<u32>;
Acceptance criteria
Testing checklist (tests/event_tests.rs)
event::create_event(src/event.rs) only charges a flatcreation_feethatgoes to the global
treasury(event.rs:99-101) — this is a platformanti-spam fee, not a prize pool. There is currently no way for a creator to
fund a prize pool or define how it's split among winners.
src/token.rshasunused helpers (
collect_entry_fee,distribute_winnings,calculate_winnings) that hint this was planned but never wired up.Goal
Let a creator deposit an XLM prize pool when creating an event, and define what
percentage of it each leaderboard rank receives (e.g.
[40, 30, 20, 5, 5]fortop 5).
Requirements
Eventstruct gains:New constants in
src/storage_types.rs:event::create_eventsignature gains:New
EventErrorvariants:InvalidPrizePool = 13—prize_pool < 0InvalidRewardDistribution = 14— any of:prize_pool > 0andreward_distribution.is_empty()reward_distribution.len() > MAX_REWARD_RANKS== 0or> 100sum(reward_distribution) != 100(only enforced whenprize_pool > 0;if
prize_pool == 0,reward_distributionmust be empty — this is a"fun event", no payouts)
InsufficientPrizePoolFunds = 15— creator's XLM balance <prize_poolFlow changes in
create_event:reward_distributionas above.prize_pool > 0: transferprize_poolfromcreatortoenv.current_contract_address()(escrow) — this is a second,separate transfer from the existing
creation_fee → treasurytransfer.Do not conflate the two.
prize_pool,reward_distribution,is_finalized: falseonEvent.(Symbol("event"), Symbol("prize_pool_funded"))with(event_id, prize_pool, reward_distribution).New read-only views (
src/views.rs+lib.rs):Acceptance criteria
prize_poolandreward_distributionat creationprize_poolXLM moves from creator to the contract address (verifyvia
TokenClient::balancein tests), separate from the creation feeInvalidRewardDistributioncases are rejected with clear errorsprize_pool == 0requires an emptyreward_distribution(fun events with no payout)Testing checklist (
tests/event_tests.rs)test_create_event_with_prize_pool_escrows_funds— assert contract's XLMbalance increases by
prize_pooland creator's decreases bycreation_fee + prize_pooltest_create_event_reward_distribution_must_sum_to_100—[50, 30, 10]→ errortest_create_event_too_many_reward_ranks— 6 entries → errortest_create_event_zero_entry_in_distribution_rejected—[100, 0]→ errortest_create_event_insufficient_balance_for_prize_pooltest_create_event_zero_prize_pool_requires_empty_distributiontest_get_event_prize_pool_and_distribution_views