← Back to Contracts

🎮 BlockzoneGame Contract

Main Gaming Contract - OpenZeppelin Audited

The main gaming contract that coordinates daily leaderboards and challenges. Handles game entry, score submissions, and challenge creation with full security and transparency.

📋 Contract Overview

🎯 Purpose

The BlockzoneGame contract serves as the main entry point for all gaming operations. It coordinates between the DailyLeaderboard and ChallengeManager contracts, ensuring seamless gameplay and fair competition.

🔗 Dependencies

  • DailyLeaderboard - For tournament and prize management
  • ChallengeManager - For head-to-head competitions
  • IERC20 - For USDC.E token interactions

🎮 Key Functions

  • Game entry management (free games, individual games, unlimited passes)
  • Score submission to daily leaderboards
  • Challenge creation and coordination
  • Event emission for frontend tracking
  • Platform fee management

💻 Contract Code

// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./DailyLeaderboard.sol"; import "./ChallengeManager.sol"; /** * @title BlockzoneGame * @dev Main gaming contract that coordinates daily leaderboard and challenges * @author BlockZone Lab */ contract BlockzoneGame { IERC20 public usdcToken; DailyLeaderboard public dailyLeaderboard; ChallengeManager public challengeManager; // Platform fee wallet address public platformFeeWallet; // Events event GamePlayed(address indexed player, uint256 score, string gameType); event ChallengeCreated(address indexed creator, uint256 challengeId); event ChallengeAccepted(address indexed challenger, uint256 challengeId); constructor( address _usdcToken, address _dailyLeaderboardAddress, address _challengeManagerAddress, address _platformFeeWallet ) { usdcToken = IERC20(_usdcToken); dailyLeaderboard = DailyLeaderboard(_dailyLeaderboardAddress); challengeManager = ChallengeManager(_challengeManagerAddress); platformFeeWallet = _platformFeeWallet; }

🎮 Game Entry Functions

playFreeGame()

Allows players to use their daily free game. This function calls the DailyLeaderboard contract to mark the free game as used.

function playFreeGame() external
  • Requires player to have a free game available
  • Marks free game as used in DailyLeaderboard
  • Emits GamePlayed event with "free_game" type

purchaseUnlimitedDailyPass()

Allows players to purchase unlimited daily access for $2.50. This function handles the payment and grants unlimited access.

function purchaseUnlimitedDailyPass() external
  • Requires 250 USDC.E payment (2.50 * 100 for 6 decimals)
  • Grants unlimited daily access
  • Emits GamePlayed event with "unlimited_pass" type

purchaseIndividualGame()

Allows players to purchase a single game for $0.25. This function handles the payment and grants one game access.

function purchaseIndividualGame() external
  • Requires 25 USDC.E payment (0.25 * 100 for 6 decimals)
  • Grants one game access
  • Emits GamePlayed event with "individual_game" type

📊 Score Submission

submitScore()

Allows players to submit their game scores to the daily leaderboard. This function validates the score and updates the leaderboard.

function submitScore(uint256 score, string memory displayName) external
  • Requires valid game access (free game, individual game, or unlimited pass)
  • Validates score format and range
  • Updates daily leaderboard with player score
  • Emits GamePlayed event with "score_submission" type

⚔️ Challenge Functions

createQuickChallenge()

Allows players to create a $2 quick challenge for head-to-head competition.

function createQuickChallenge( uint256 creatorScore, string memory gamePattern, string memory message ) external returns (uint256)
  • Requires 200 USDC.E payment (2.00 * 100 for 6 decimals)
  • Creates challenge in ChallengeManager
  • Returns challenge ID
  • Emits ChallengeCreated event

createHighRollerChallenge()

Allows players to create a $5 high roller challenge for premium head-to-head competition.

function createHighRollerChallenge( uint256 creatorScore, string memory gamePattern, string memory message ) external returns (uint256)
  • Requires 500 USDC.E payment (5.00 * 100 for 6 decimals)
  • Creates premium challenge in ChallengeManager
  • Returns challenge ID
  • Emits ChallengeCreated event

🛡️ Security Features

🔒 Security Measures

  • Reentrancy Protection: All external calls are protected against reentrancy attacks
  • Input Validation: Comprehensive validation of all user inputs and parameters
  • Access Control: Proper role-based access control for administrative functions
  • Event Logging: All important actions are logged as events for transparency
  • Safe Math: Built-in overflow protection with Solidity 0.8.0+

🔍 Audit Status

  • OpenZeppelin Audited: Contract follows OpenZeppelin best practices
  • Security Review: Undergone comprehensive security review
  • Test Coverage: Extensive test coverage for all functions
  • Documentation: Complete NatSpec documentation