GameFactory

GameFactory

Inherits: IGameFactory, Ownable, Pausable

Facilitates the creation of new games

State Variables

MAXIMUM_GAME_CREATION_FEE

This uses 6 decimals because the contract uses USDC as the fee token

uint256 public constant MAXIMUM_GAME_CREATION_FEE = 100e6;

usdc

Address of the USDC token

IERC20 public immutable usdc;

vault

Address of the Vault contract

Vault public immutable vault;

revealer

Address of the Revealer contract

address public revealer;

gameDuration

Duration of newly created games

uint256 public gameDuration;

claimableAfter

Duration at which the revealer can reveal the cards of newly created games

uint256 public claimableAfter;

maxFreeReveals

Maximum amount of free reveals for newly created games

uint256 public maxFreeReveals;

gameCreationFee

Fee of game creation in USDC

uint256 public gameCreationFee;

nextGameId

ID of the next Game

uint256 public nextGameId = 0;

userGames

Number of games a user has created

mapping(address user => uint256 games) public userGames;

referrals

Referrals program

mapping(address referee => address referrer) public referrals;

referrerInvites

Number of players a referrer has invited

mapping(address referrer => uint256 invites) public referrerInvites;

Functions

constructor

Initializes the GameFactory contract with specified parameters

constructor(
    IERC20 _usdc,
    Vault _vault,
    address _revealer,
    uint256 _gameDuration,
    uint256 _claimableAfter,
    uint256 _maxFreeReveals,
    uint256 _gameCreationFee
) Ownable(msg.sender);

Parameters

Name
Type
Description

_usdc

IERC20

The address of the USDC token

_vault

Vault

The address of the vault that will call the createGame function

_revealer

address

A trusted address used to initialize games and reveal player guesses

_gameDuration

uint256

The duration of each game, after which games expire

_claimableAfter

uint256

The duration which the user can claim their win if revealer does not reveal

_maxFreeReveals

uint256

The maximum amount of free reveals a player can request

_gameCreationFee

uint256

The fee required for players to create games

pause

Pauses the GameFactory from creating new games

Emits Paused event

function pause() external onlyOwner;

unpause

Unpauses the GameFactory from creating new games

Emits Unpaused event

function unpause() external onlyOwner;

setGameCreationFee

Changes the fee required to create a new game

Emits GameFeeChanged event

function setGameCreationFee(uint256 _gameCreationFee) external onlyOwner;

Parameters

Name
Type
Description

_gameCreationFee

uint256

The new fee amount in USDC

setGameDuration

Changes the duration of future games

Emits GameDurationChanged event

function setGameDuration(uint256 _gameDuration) external onlyOwner;

Parameters

Name
Type
Description

_gameDuration

uint256

The new duration in seconds

setClaimableAfter

Changes the claimable duration of future games

Emits ClaimableAfterChanged event

function setClaimableAfter(uint256 _claimableAfter) external onlyOwner;

Parameters

Name
Type
Description

_claimableAfter

uint256

The new duration in seconds

setMaxFreeReveals

Changes the maximum amount of free reveals a player can request for future games

Emits MaxFreeRevealsChanged event

function setMaxFreeReveals(uint256 _maxFreeReveals) external onlyOwner;

Parameters

Name
Type
Description

_maxFreeReveals

uint256

The amount of free reveals a player can request

setRevealer

Changes the manager address for creating new games

Emits RevealerChanged event

function setRevealer(address _revealer) external onlyOwner;

Parameters

Name
Type
Description

_revealer

address

The new manager address

createGame

Creates a new game using the GameFactory contract and stores related data

The caller must pay at least the gameCreationFee amount to create a game

Emits GameCreated event

function createGame(address _referrer) external whenNotPaused returns (uint256 id, address gameAddress);

Parameters

Name
Type
Description

_referrer

address

The referrer of the player. Could be the 0x00 address if already set or if the player does not want to set one

Returns

Name
Type
Description

id

uint256

The ID of the newly created game

gameAddress

address

The address of the newly created game

games

Retrieves the details of a specific game

function games(uint256 _gameId) external view returns (GameDetails memory);

Parameters

Name
Type
Description

_gameId

uint256

The ID of the game

Returns

Name
Type
Description

<none>

GameDetails

Details of the specified game

Types

gameDetails

struct GameDetails {
    address player;
    address revealer;
    address gameAddress;
    uint256 gameDuration;
    uint256 claimableAfter;
    uint256 maxFreeReveals;
    uint256 gameCreationFee;
    uint256 gameCreatedAt;
}

Last updated