Shonen-Labs/Roster-Rumble

CONTRACT: Prize Pool Contract

Open

#25 aperta il 23 apr 2025

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)TypeScript (11 fork)auto 404
ODHack 14contractgood first issue

Metriche repository

Star
 (4 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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

Guida contributor