- Introduction
- Prerequisites
- Quickstart
- FourMarket Contract
- Market Contract
- Token Contract
- User Actions
- Summary
- Note
This document provides a brief overview of the FourMarket
, Market
, and Token
smart contracts. These contracts form a decentralized prediction market platform where users can create markets, place bets on outcomes, and receive rewards based on the actual results.
Before setting up the project, ensure you have the following installed:
-
Git: Version control system for cloning and managing repositories.
- Installation: Follow the official Git installation guide.
- Verification: Run
git --version
in your terminal. You should see output likegit version x.x.x
.
-
Foundry: A blazing fast, portable, and modular toolkit for Ethereum application development written in Rust.
- Installation: Use the command provided at Foundry's official website.
- Verification: Run
forge --version
in your terminal. Expected output is similar toforge x.x.x
.
-
Yarn: Fast, reliable, and secure dependency management for JavaScript projects.
- Installation: Follow the Yarn installation guide.
# Install Yarn globally using npm npm install --global yarn
- Verification: Run the following command to confirm installation:
yarn --version
- Installation: Follow the Yarn installation guide.
Follow the steps below to set up the project locally:
# Clone the repository
git clone https://github.com/monnidev/4Market.git
# Navigate to the project directory
cd 4Market
# Compile
forge build
- Acts as a factory and registry for creating and managing individual prediction markets.
- Allows users to create new markets with specific parameters.
-
Create Market: Users call the
createMarket()
function with the desired parameters:_question
: The question or event for the market._details
: Additional information about the market._deadline
: Timestamp when betting closes._resolutionTime
: Time window for resolving the market._resolver
: Address responsible for resolving the market.
-
Market Registry: Newly created markets are stored in the
markets
mapping with a uniquemarketId
.
- Represents an individual prediction market.
- Handles bet placement, market resolution, and reward distribution.
-
Bet Placement:
- Users place bets by sending Ether and specifying an outcome (
Yes
orNo
). - Bets can only be placed before the
i_deadline
. - Users receive
YesToken
orNoToken
representing their stake.
- Users place bets by sending Ether and specifying an outcome (
-
Market Resolution:
- After the betting deadline, the designated
i_resolver
can resolve the market by callingresolve()
with the final outcome. - Resolution must occur within the
i_resolutionTime
window.
- After the betting deadline, the designated
-
Reward Distribution:
- Users can claim rewards by calling
distribute()
after the market is resolved. - Rewards are proportional to their stake in the winning outcome.
- Tokens are burned upon claiming rewards.
- Users can claim rewards by calling
-
Inactivity Cancellation:
- If the market is not resolved within the resolution window, anyone can call
inactivityCancel()
to cancel the market. - Users can then retrieve their original bets.
- If the market is not resolved within the resolution window, anyone can call
-
For Participants:
- Place a Bet:
- Call
bet(outcomeType _betOutcome)
with your chosen outcome. - Send the amount of Ether you wish to bet.
- Call
- Claim Rewards:
- After the market is resolved, call
distribute()
to claim your rewards.
- After the market is resolved, call
- Place a Bet:
-
For Market Creators:
- Create a Market:
- Call
createMarket()
on theFourMarket
contract with the desired parameters. - Set yourself or another trusted entity as the
i_resolver
.
- Call
- Create a Market:
-
For Resolvers:
- Resolve the Market:
- After the betting deadline and within the resolution window, call
resolve(outcomeType _finalResolution)
with the actual outcome.
- After the betting deadline and within the resolution window, call
- Resolve the Market:
- ERC20 tokens representing users' stakes in a market outcome.
- Two types:
YesToken
andNoToken
.
-
Minting:
- Only the market contract (
i_deployer
) can mint tokens when users place bets.
- Only the market contract (
-
Burning:
- Tokens are burned when users claim rewards.
- Participants: Place bets on market outcomes and claim rewards based on actual results.
- Creators: Use the
FourMarket
contract to create new markets. - Resolvers: Responsible for setting the final outcome of a market within the specified resolution window.
- The
Token
contract no longer mints an initial token upon deployment. This means that initial token supplies start at zero, and calculations involving total supply should account for this to avoid division by zero errors.