project screenshot 1
project screenshot 2
project screenshot 3
project screenshot 4
project screenshot 5
project screenshot 6

FanPredix

FanPredix is a decentralized, peer-to-peer prediction market platform designed specifically for sports events, leveraging team-specific Fan Tokens on the Chiliz blockchain.

FanPredix

Created At

ETHOnline 2024

Winner of

trophy

2nd place

Project Description

FanPredix: Fan Token-Powered P2P Sports Prediction Market Overview

FanPredix is a decentralized, peer-to-peer prediction market platform designed specifically for sports events, leveraging team-specific Fan Tokens on the Chiliz blockchain. It enables official team managers to create markets for their matches, allowing fans to participate using the team's Fan Tokens. This creates an engaging, team-centric betting experience while providing additional utility for Fan Tokens.

Key Features

Team-specific markets using Fan Tokens Peer-to-peer order matching system Back and lay betting options Risk-free protocol operation Automated fee collection for platform sustainability

Roles and Responsibilities

Admin Deploy the FanPredix contract Manage contract configuration (e.g., platform fees, minimum bet amounts) Add official team addresses with TEAM_ROLE

Team Manager (TEAM_ROLE) Create official prediction markets for their events Update team information (name, Fan Token address, active status) Resolve markets by proposing the final outcome

Users (Fans) Place back or lay orders on market outcomes using team-specific Fan Tokens Cancel their own unmatched orders Redeem winnings after market resolution

Fan Token Integration Fan Tokens are at the core of FanPredix's functionality:

Team Registration: Each team is associated with its specific Fan Token. Market Creation: Team managers create markets using their team's Fan Token. Betting: Users place bets using the specified Fan Token for each market. Winnings: Profits are paid out in Fan Tokens. Future Feature: Governance voting for dispute resolution using Fan Tokens.

User Flow Connect Wallet: Users connect their wallet containing Fan Tokens to the FanPredix dApp. Browse Markets: View available prediction markets created by official team managers. Place Order: Choose an outcome, specify amount and odds, and place a back or lay order using the required Fan Tokens. Order Matching: Orders are matched peer-to-peer based on compatible odds and amounts. Monitor: Track the progress of the event and the market. Redeem Winnings: If successful, claim winnings after market resolution, minus the platform fee.

Team Manager Flow Team Registration: Admin adds the team manager address with TEAM_ROLE. Update Team Info: Team manager can update team name, Fan Token address, and active status. Create Market: Set event details: category, question, description, options Define start and end times Monitor Market: Observe user participation. Resolve Market: After the event concludes, propose the final outcome.

Technical Implementation

Key Functions addTeam: Add a new team with TEAM_ROLE (admin only) updateTeam: Update team information (team manager only) createMarket: Create a new prediction market (TEAM_ROLE only) placeOrder: Place a back or lay order on a specific outcome cancelOrder: Cancel an existing unmatched order _tryMatchOrder: Internal function to match compatible orders resolveMarket: Propose the final outcome of a market (TEAM_ROLE only) redeemWinnings: Claim winnings for successful bets

Fund Flow Order Placement: When a user places an order, the required Fan Tokens are transferred to the contract. Order Matching: Upon successful matching, the contract holds the Fan Tokens from both parties. Market Resolution: After the market is resolved by the team manager, winners can claim their winnings. Platform Fee: A configurable percentage of each winning bet is deducted as a platform fee before payout. Refunds: Unmatched orders are automatically refunded when the market is resolved. Platform Profitability FanPredix ensures sustainable operations through an automated fee collection mechanism:

A small, configurable percentage fee is deducted from winning bets. Fees are collected at the time of winning redemption, ensuring the protocol never holds liability. Collected fees are sent to a designated treasury address for platform maintenance and development. Security Considerations Role-based access control (RBAC) for admin and team manager functions Time-based checks to prevent actions on expired or invalid markets Careful handling of Fan Token transfers and storage No protocol liability, as all bets are peer-to-peer and fees are collected from winnings Future Enhancements Implementation of a governance voting system for dispute resolution using Fan Tokens Integration with Chiliz blockchain for real-time sports data feeds Enhanced analytics and reporting for users and team managers Multi-language support for global accessibility

Smart Contract: https://github.com/pratikasr/FanPredix Frontend Dapp: https://github.com/pratikasr/fanpredix-frontend Deployment on chiliz testnet: https://testnet.chiliscan.com/address/0x239EDd859C51b8b7ac88F55Eed96F380F0bD816d FanToken used in project: https://testnet.chiliscan.com/token/0x96808b9fbA6301e31BfD2dc4EA98fF0ed91fA6c5

How it's Made

How it's made FanPredix is a decentralized sports prediction platform that leverages blockchain technology to create a transparent and engaging ecosystem for sports fans. Here's a detailed breakdown of how we built this project:

Smart Contract (Backend) Technologies Used: Solidity 0.8.0+ OpenZeppelin Contracts Hardhat development environment Implementation Details: Contract Structure: We developed a single main contract FanPredix that inherits from OpenZeppelin's AccessControl. This allows for role-based access control, crucial for differentiating between admins, team managers, and regular users.

Data Models: We implemented complex data structures like Team, Market, Order, and Bet to represent the core entities of our prediction market system. These structures are stored efficiently using mappings to optimize gas costs.

Market Creation and Management: Team managers can create markets using the createMarket function. We implemented checks to ensure only authorized team managers can create markets for their teams.

Order Matching System: We developed a peer-to-peer order matching system within the placeOrder function. The _tryMatchOrder internal function attempts to match new orders with existing opposite orders, creating bets when matches are found.

Token Integration: We integrated ERC20 token functionality to handle Fan Tokens. The contract interacts with these tokens for placing orders and redeeming winnings, ensuring a seamless token economy within the platform.

Market Resolution: We implemented a secure market resolution process where only authorized team managers can resolve their markets. The resolveMarket function updates the market status and sets the winning outcome.

Winnings Redemption: Users can redeem their winnings using the redeemWinnings function, which calculates the payout based on the resolved market outcome and transfers the appropriate amount of Fan Tokens.

Platform Fee Mechanism: We incorporated a platform fee system where a configurable percentage of winnings is sent to a treasury address, ensuring the sustainability of the platform.

Notable Challenges: Implementing an efficient order matching system while considering gas optimization was particularly challenging. We had to carefully balance between on-chain and off-chain operations to ensure a smooth user experience without excessive gas costs. Ensuring the security and integrity of the market resolution process required careful consideration of access controls and timing mechanisms. Frontend Application Technologies Used: Next.js 13 (React framework) TypeScript Tailwind CSS for styling Framer Motion for animations ethers.js for Ethereum interaction React Icons for UI icons Implementation Details: Responsive Design: We used Tailwind CSS to create a fully responsive design that works seamlessly across desktop and mobile devices. The use of Tailwind's utility classes allowed for rapid development and consistent styling.

Interactive UI: Framer Motion was extensively used to create smooth animations and transitions, enhancing the overall user experience. This is particularly evident in the header component and the team manager page.

Wallet Integration: We implemented MetaMask wallet connection functionality in the header component. This allows users to connect their Ethereum wallets and interact with the smart contract seamlessly.

Dynamic Routing: Next.js's dynamic routing capabilities were utilized to create team-specific and market-specific pages. This allows for a clean URL structure and efficient navigation.

State Management: We used React's built-in hooks (useState, useEffect) for local state management. For more complex state management needs, we implemented custom hooks to encapsulate logic and promote reusability.

Data Visualization: We integrated chart.js through react-chartjs-2 to create interactive and visually appealing charts for market performance and fan engagement statistics.

Modular Component Structure: The application is built using a modular component structure, with reusable components like the Header, Footer, and various card components. This approach enhances maintainability and allows for easy scaling of the application.

Server-Side Rendering: We leveraged Next.js's server-side rendering capabilities to improve initial load times and SEO performance.

Notable Challenges: Implementing a seamless wallet connection experience while handling different connection states and error scenarios required careful consideration of user flows and error handling. Creating an intuitive and engaging UI for complex betting mechanisms, especially for the order placement and market resolution processes, required multiple iterations and user feedback. Partner Technologies: We utilized OpenZeppelin's battle-tested smart contract libraries to ensure the security and reliability of our smart contract. This significantly reduced the risk of common vulnerabilities and allowed us to focus on implementing our core business logic. The integration of MetaMask provided a secure and widely adopted solution for wallet management and transaction signing, enhancing the trustworthiness of our platform. By combining these technologies and approaches, we were able to create a robust, user-friendly, and highly interactive decentralized sports prediction platform that offers a unique and engaging experience for sports fans and crypto enthusiasts alike.

background image mobile

Join the mailing list

Get the latest news and updates