thirdweb

GamePot

Gamepot - a prize pool contract for off-chain games

GamePot

Used at https://theuniverse.gg

Gamepot is a prize pooling contract for off chain games. Players add credits and join games with an ERC20 that's configured during creation of the game. The top x% of players are then paid out of the prize pool based on a leaderboard. A percent of the prize pool goes to the contract deployer as well as the game host.

The "off chain" part means that this assumes the contract is controlled by something off chain. Because of this, atomicity assumptions cannot be made and this shows itself in the startGame function:

function startGame(uint game_id, address[] calldata players)

The game controller (off chain) must tell the contract which players actually made it into the game. This is to handle the race condition of:

  • game controller starts game
  • client doesn't yet know the start game transaction is pending
  • client calls join game
  • game controller sees the game has started and begins the game (spawning joined clients in the game arena for example)
  • game controller doesn't know there is a client join in-progress
  • client pays but doesn't get to play

The contract will refund all players who are not in that players array but have paid to join.

API Reference:

Player Functions

function joinGame(uint game_id) // join a game that hasn't started yet

function cashOut(uint game_id) // transfer all credits not locked into an ongoing game to the player's wallet

function addCredits(uint game_id, uint amount) // add credits to balance

function getMyCreditBalance(uint game_id) // check my credit balance

function getCreditBalanceOf(uint game_id, address addr) // check balance of another player

Moderation Management

Adding or removing mods can only be done by an owner.

function addMod(uint game_id, address mod) // add a mod to a game

function removeMod(uint game_id, address mod) // remove a mod from a game

function isModOrOwner(uint game_id, address addr) // checks if address is a mod or owner for a game

Game Management

All game state changes must be called by a mod or owner. Owner is the creator of the game.

function createGame(uint game_id, ERC20 currency, uint price, uint percentageOfPlayersPaidOut, uint royaltyPercentOfTotalPrizePool) // create a game

function startGame(uint game_id, address[] calldata players) // start the game, locking in players and refunding those not in players

function completeGame(uint game_id, address[] calldata leaderboard) // complete the game and payout winners + royalties

function resetGame(uint game_id) // reset game after it has been completed

function cancelGame(uint game_id) // cancels game and refunds everyone


Add Credits

(addCredits)

nonpayable

Inputs

game_id

uint256

amount

uint256

Published by

View all contracts

Details

  • Publish Date

    Oct 13, 2022

  • Licenses

    MIT, Unlicense

  • Learn more about Publish