📟Predict Game

PredictGame is a part of a blockchain-based prediction game that leverages smart contracts for its operations. The contract is designed for a game where players predict whether a certain asset's price will go up or down within a specified time frame.

Imports and Dependencies

  • OpenZeppelin's Ownable.sol: Ensures that certain functionalities are restricted to the contract owner.

  • Predict.sol: A contract that manages prediction logic or game settings.

  • DataFeed.sol: Interface to an external data feed, for fetching real-world asset prices.

  • PredictBet.sol: Represents an individual bet within the game.

Main Components

  • DataFeed: A reference to an data feed contract that provides the asset prices.

  • Predict: A contract that manages the core functionalities of the prediction game.

  • interval: The time interval between prediction rounds.

  • bonus: An additional reward percentage for winning bets.

  • symbol: Symbol of the asset being predicted on.

  • active: A flag to activate or deactivate the game.

  • lastCalculatedRound: Keeps track of the last round that was calculated.

  • duration: How long a prediction round lasts in count of intervals.

  • threshold: Maximum allowed time difference for fetching the end data of a round.

Events

  • BetCreated: Emitted when a new bet is created.

  • RoundCreated: Emitted when a new prediction round is created.

  • RoundCalculated: Emitted when a round's results are calculated.

Key Functions

Constructor

Initializes the contract with necessary parameters like the data feed address, asset symbol, game interval, bonus percentage, round duration, and threshold.

getCurrentRound

Calculates the current round based on the current timestamp and the interval.

placeBet

Allows placing a bet on the prediction of the asset's price movement. It creates a new PredictBet contract for each bet and updates the pools and bets arrays accordingly.

calculateBets

Calculates the result of bets for a specified round. It ensures the round has finished, fetches the start and end prices, and then determines whether long or short bets won. It also handles the case where the result is a draw.

Helper Functions

  • calculateDrawResult, calculateLongResult, calculateShortResult: Determine the outcome of the bets based on the price movement and distribute rewards accordingly.

  • activate, deactivate: Functions to activate or deactivate the game.

Usage

To create this contract, the Predict initializes it with the necessary parameters. Players can then place bets on asset price movements. After each round, the contract calculates the outcomes and distributes winnings based on the asset's price changes.

Last updated