PrimapePrediction Smart Contracts

Overview

PrimapePrediction is powered by a sophisticated smart contract that handles all aspects of our multi-outcome prediction markets. This page provides an overview of the key functions and how to interact with them.

Core Functions

For Market Creators

function createMarket(string memory question, string[] memory options, uint256 duration) external onlyOwnerOrCreator

Creates a new prediction market with the given question, options, and duration.

For Users

function buyShares(uint256 marketId, uint256 optionIndex) external payable

Allows users to buy shares in a specific outcome of a market.

function claimWinnings(uint256 marketId) external

Allows winners to claim their earnings after market resolution.

For Platform Owners

function resolveMarket(uint256 marketId, uint256 winningOptionIndex) external onlyOwner

Resolves a market by setting the winning outcome.

function setFeeBps(uint256 _feeBps) external onlyOwner

Updates the platform fee (in basis points).

function withdrawFees(address recipient, uint256 amount) external onlyOwner

Withdraws accumulated platform fees.

View Functions

function getMarketInfo(uint256 marketId) external view returns (string memory question, uint256 endTime, bool resolved, uint256 winningOptionIndex)
function getMarketOptions(uint256 marketId) external view returns (string[] memory)
function getUserShares(uint256 marketId, address user) external view returns (uint256[] memory)

These functions allow querying various aspects of markets and user positions.

Events

The contract emits several events to facilitate off-chain tracking of on-chain actions:

  • MarketCreated
  • SharesBought
  • MarketResolved
  • WinningsClaimed

Example: Creating and Interacting with a Market


      // Deploy the contract
      const PrimapePrediction = await ethers.getContractFactory("PrimapePrediction");
      const prediction = await PrimapePrediction.deploy();
      await prediction.deployed();

      // Create a market
      await prediction.createMarket(
        "Who will win the 2024 US Presidential Election?",
        ["Democrat", "Republican", "Other"],
        365 * 24 * 60 * 60 // 1 year duration
      );

      // Buy shares
      await prediction.buyShares(0, 1, { value: ethers.utils.parseEther("0.1") });

      // Resolve market (only owner)
      await prediction.resolveMarket(0, 1); // Assuming Republican wins

      // Claim winnings
      await prediction.claimWinnings(0);
      

Security Considerations

The PrimapePrediction contract includes several security measures:

  • Role-based access control for market creation and resolution
  • Checks for valid market IDs and option indices
  • Claim deadlines to prevent indefinitely unclaimed funds

However, as with any smart contract, users should exercise caution and understand the risks involved in participating in prediction markets.

Audits

The PrimapePrediction contract has undergone thorough auditing. You can find the latest audit reports in our GitHub repository.