πΈοΈBoxes Smart Contracts Ecosystem
BoxFactory
The Factory contract serves as a central hub for managing and creating boxes instances using a predefined contract model. This contract utilizes events to facilitate the monitoring of its activities, particularly the creation of boxes
Box Contract
Manages the details, participations, and distributions of individual predictions.
Oracle
Provides match results, acting as an external source of truth, powered via AI.
π Simplified Operation
Dynamic Deployment: Each user-initiated prediction is instantiated as a separate smart-contract, dynamically deployed via the Factory contract.
Autonomous Management: These contracts autonomously manage predictions, enforce the specific rules of each wager, and facilitate the distribution of winnings post-result validation.
Secure Interactions: The contracts guarantee that all transactions are executed securely and remain immutable once recorded on the blockchain.
BoxFactory Contract
Overview
The BoxFactory
contract serves as the foundational contract for the WhaleInTheBox platform. It is responsible for the creation and management of individual prediction events, known as "boxes." By leveraging the factory pattern, this contract allows for scalable and efficient deployment of new boxes, each encapsulating its own logic and state.
Key Functions
createBox: Allow you to create a new
Box
contract instance with specified parameters such as details, end time, maximum amount per prediction, and whether the box is public or private.setOracleAddress: Enables the contract owner to update the address of the Oracle contract, which provides outcomes for prediction events.
Key Features
Scalability: By using the factory pattern, the platform can handle an arbitrary number of prediction events without congesting a single contract.
Modularity: Each
Box
contract operates independently, promoting better organization and easier maintenance.Creator Tracking: The factory maintains a mapping of creators to the boxes they've created, facilitating easy retrieval and management.
Box Contract
Overview
The Box
contract represents an individual prediction event. It encapsulates all the logic related to managing predictions, storing participants' stakes, and settling outcomes. The contract is composed of several inherited contracts that modularize its functionality:
BoxStorage
: Handles data storage and access control.BoxBetting
: Manages prediction placements.BoxSettlement
: Handles the settlement of predictions and distribution of rewards.
Key Functions
createBox: Initializes the box with specific details, including events, game IDs, and visibility settings.
Interactions with Other Contracts
Oracle Contract: Utilizes the Oracle to obtain the outcome of the prediction event for settlement.
BoxStorage Contract
Overview
BoxStorage
is an abstract contract that provides the foundational data structures and access control mechanisms for the Box
contract. It defines the roles, events, and core variables used across the BoxBetting
and BoxSettlement
contracts.
Data Structures
Bet: Stores information about each participant's prediction and stake.
BoxEvent: Represents specific events or conditions tied to the prediction.
BoxDetails: Aggregates all relevant information about the box.
BoxBetting Contract
Overview
The BoxBetting
contract extends BoxStorage
and handles all functionalities related to placing predictions. It ensures that participants adhere to the rules set for each box, such as maximum stake amounts and time constraints.
Key Functions
createBet: Allows participants to place a prediction using native tokens.
createBetWithAmount: Enables participants to place a prediction using ERC20 tokens.
Features
Prediction Validation: Converts string inputs to boolean predictions for processing.
Stake Management: Updates the total amount and individual stakes upon each prediction.
Public and Private Boxes: Enforces access control based on whether a box is public or private.
BoxSettlement Contract
Overview
BoxSettlement
is responsible for finalizing prediction events and distributing rewards to the participants. It interacts with the Oracle contract to obtain the outcome and calculates winnings based on participants' stakes.
Settlement Process
Outcome Retrieval: Fetches the result from the Oracle contract.
Outcome Recording: Updates the box's state to reflect the settled outcome.
Winnings Calculation: Determines each participant's winnings based on their stake and the total pool.
Fee Deduction: Applies a fee percentage, transferring it to the staking address.
Reward Distribution: Transfers winnings to participants.
Key Functions
settleBetFromOracle: Fetches and records the outcome from the Oracle.
claimWinnings: Allows participants to claim their rewards after settlement.
getWinningsToClaim: Provides a view function for participants to check their potential winnings.
Oracle Contract
The Oracle Contract serves as a source of information to settle Boxes with announced Eventsβ outcomes. Once a Box is settled its Outcome may not be altered.
Key Functions
Constructor
Purpose: Initializes the Oracle contract by setting up roles and permissions.
Parameters:
initialAI
: The address granted theAI_ROLE
, typically an AI or external system responsible for providing outcomes.
setResult
Purpose: Allows an AI to set the outcome of a prediction event (box).
Parameters:
boxId
: The address of theBox
contract whose outcome is being set._outcome
: The boolean result of the prediction event (true
orfalse
).
Requirements:
Caller must have the AI
_ROLE
.The result for the
boxId
must not have been settled previously.
getResult
Purpose: Retrieves the outcome of a prediction event for a given
boxId
.Parameters:
boxId
: The address of theBox
contract whose outcome is being queried.
Returns:
isSettled
: A boolean indicating whether the result has been set.outcome
: The boolean result of the prediction event.
Interactions with Other Contracts
Box Contracts
Outcome Retrieval:
Box
contracts call thegetResult
function to retrieve the outcome of their prediction event during the settlement process.Result Dependency: The settlement logic within a
Box
contract depends on the outcome provided by the Oracle.
Autonomous Functionality
The WhaleInTheBox smart contracts are designed to operate autonomously, minimizing the need for external intervention after deployment. Key aspects include:
Automated Settlement: Boxes can be settled automatically through the Oracle without manual input.
Self-Contained Boxes: Each
Box
contract functions independently, ensuring that issues in one do not affect others.
Last updated