Skip to content

CONTRACT: Prize Pool Contract #25

@PoulavBhowmick03

Description

@PoulavBhowmick03

Title: Automated Prize Distribution Logic
Description
Create contract to manage contest entry fees and prize distributions.

Acceptance Criteria:

  • Tracks locked funds per contest
  • Distributes prizes to top 3 positions:
    • 1st: 50%
    • 2nd: 30%
    • 3rd: 20%
  • Allows withdrawals after contest conclusion
  • Prevents double entry with participant mapping

Technical Details:

#[starknet::contract]
mod PrizePool {
    #[storage]
    struct Storage {
        balances: LegacyMap<(felt252, felt252), u64>, // (contest_id, user)
        prize_distribution: LegacyMap<felt252, (u64, u64, u64)>
    }

    #[external(v0)]
    fn lock_funds(ref self: ContractState, contest_id: felt252, amount: u64) {
        let user = get_caller_address();
        assert(amount > 0, 'Invalid amount');
        
        let current = self.balances.read((contest_id, user));
        self.balances.write((contest_id, user), current + amount);
    }

    #[external(v0)]
    fn distribute_prizes(
        ref self: ContractState, 
        contest_id: felt252,
        ranks: Array<felt252> // [1st, 2nd, 3rd]
    ) {
        assert(ranks.len() == 3, 'Invalid ranks');
        let total = self.total_prize_pool.read(contest_id);
        
        let amounts = (
            total * 50 / 100, // 50%
            total * 30 / 100, // 30%
            total * 20 / 100  // 20%
        );

        // Transfer logic
        self._transfer(ranks[0], amounts.0);
        self._transfer(ranks[1], amounts.1);
        self._transfer(ranks[2], amounts.2);
        
        self.prize_distribution.write(contest_id, amounts);
    }
}

Notes:

  • Add emergency withdrawal safety
  • Implement decimal precision handling
  • Add contest duration checks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions