# Peer2PlayGenericStakingContract

The `Peer2PlayGenericStakingGames` contract provides a flexible framework for managing staking-based multiplayer games. Key features include game and match lifecycle management, customizable fee structures, and support for private and public matches. The contract ensures security, scalability, and ease of integration into decentralized ecosystems.

***

### 2. **Imports Used & Their Significance**

1. **`ReentrancyGuard`**: Prevents reentrancy attacks.
2. **`Ownable`**: Grants admin privileges for sensitive functions.
3. **`Pausable`**: Enables emergency stops for games or the entire platform.
4. **`SafeERC20`**: Ensures secure interactions with ERC20 tokens.

***

### 3. **State Variables**

#### Protocol-Level Variables

* **`matchCounter`**: Ensures unique match IDs.
* **`protocolFee`**: Fee percentage applied to all matches.
* **`drawFee`**: Fee percentage for drawn matches.
* **`FEE_DENOMINATOR`**: Denominator for basis point calculations.

#### Game & Match Mappings

* **`gameUids`**: Links game UIDs to their metadata.
* **`matches`**: Stores match details by ID.
* **`allowedTokens`**: Defines eligible ERC20 tokens and their minimum stakes.

***

### 4. **Function Descriptions**

#### Game Management

1. **`addGame`**: Adds a new game to the platform.
2. **`updateGameFee`**: Allows game owners to adjust their game fee.
3. **`pauseGame`**: Temporarily halts a game for maintenance or issues.
4. **`unpauseGame`**: Resumes operations for a paused game.
5. **`removeGame`**: Deletes a game from the platform.

#### Fee & Token Management

1. **`setProtocolFee`**: Sets platform-wide fees for matches.
2. **`setDrawFee`**: Defines fees for matches that end in a draw.
3. **`allowToken`**: Adds or updates eligible staking tokens.

#### Match Lifecycle

1. **`createMatch`**: Initializes a new match with customizable parameters.
2. **`joinMatch`**: Enables players to join matches, verifying authorization for private matches.
3. **`submitMatchResult`**: Submits results and distributes rewards or refunds.
4. **`cancelMatch`**: Cancels a match and refunds participants.

#### Internal Utilities

1. **`_handleDraw`**: Handles refunds for drawn matches.
2. **`_amountAfterCut`**: Computes net amount after deducting fees.
3. **`_transferFunds`**: Handles secure token and native currency transfers.
