# Fantasy Manager League ## Potential Names - Back the Boss - Backroom Bets - In Form - The Manager Game # ๐Ÿง  Architecture & Spec Back your favorite Fantasy Premier League (FPL) manager. Win if they top the table. Built for Farcaster, fully decentralized, and on-chain. --- ## ๐ŸŽฎ Game Concept Summary - Users **predict** which FPL manager will perform best over a defined **Season**. - Each **Season** runs for a few FPL **Gameweeks** (e.g., ~2 months). - After the Season ends: - Managers are ranked based on FPL points between the Season's start & end. - **Top 3 (Gold, Silver, Bronze)** managers are determined. - Users who correctly predicted those managers share the prize pool. - **Managers also get a commission** from the winnings. - A small **fee goes to the treasury** for future development. --- ## ๐Ÿ“– Core Definitions ### ๐Ÿ• Season - Represents a prediction contest running for multiple **Gameweeks**. - Defined by: - `startGameweek` - `endGameweek` - Snapshot of managers is taken at the beginning (locked). - Scores between `startGameweek` and `endGameweek` determine final leaderboard. ### ๐Ÿ” Gameweek - Follows the official FPL schedule (GW1, GW2, ...). - Used to compute managers' scores weekly. - Not used for payouts individually but useful for leaderboard updates. --- ## ๐Ÿงฑ Smart Contract Overview ### Core Concepts ```solidity struct Season { uint256 id; uint256 startGameweek; uint256 endGameweek; bytes32 leagueRoot; // Merkle root of manager snapshot string leagueCID; // IPFS CID of snapshot JSON bytes32 finalScoreRoot; // Merkle root of final leaderboard uint256[3] topManagers; // Gold, Silver, Bronze bool ended; } ``` ### Functionality | Functionality | On-Chain? | |-------------------------------|-----------------| | Create Season | โœ… (admin) | | Predict Manager | โœ… | | Lock Season / Snapshot | โœ… (Merkle root) | | Store Weekly Gameweek Scores | โŒ (off-chain) | | Finalize Season | โœ… | | Claim Winnings (Users + Managers) | โœ… | --- ## ๐ŸŸก Weekly Leaderboard & Gameweek Scores ### Why Scores Arenโ€™t On-Chain Weekly - Writing all scores on-chain every week would be **too expensive**. - Weekly scores are **not used for payouts**, only for showing a live leaderboard. ### โœ… Weekly Score Flow (Off-Chain + IPFS) 1. After each Gameweek: - A backend (cron or Chainlink Function) fetches scores via the FPL API. - Generates a Merkle tree from manager scores. - Uploads the full scores as JSON to **IPFS**. - Publishes: - `scoresCID` (IPFS hash) - `scoresMerkleRoot` (optional for verification) 2. Frontend: - Fetches the latest IPFS CID from a trusted source (e.g. ENS text record or hosted metadata file). - Loads and optionally verifies the score JSON. - Renders the **live leaderboard** in the UI. 3. At Season End: - Only the final scores between `startGameweek โ†’ endGameweek` are submitted on-chain via Merkle root and IPFS CID. | Time | Scores | Stored On-Chain? | |--------------|--------|------------------| | Every Gameweek | โœ… (IPFS) | โŒ (off-chain only) | | Season End | โœ… (IPFS) | โœ… (final root + CID) | ### Optional: To increase transparency, submit weekly Merkle roots via: ```solidity function submitWeeklyScores(uint256 gameweekId, bytes32 root) external onlyAdmin ``` --- ## ๐Ÿช™ Prize Distribution Example Assuming `1 ETH` prize pool: - 5% โ†’ Treasury - 95% distributed: - ๐Ÿฅ‡ 70% โ†’ Gold predictors - 80% to users - 20% to manager - ๐Ÿฅˆ 20% โ†’ Silver - ๐Ÿฅ‰ 10% โ†’ Bronze If a winning manager wasnโ€™t picked: - That reward share can go to Treasury or roll over. --- ## โš™๏ธ Tech Stack ### ๐Ÿ”— Smart Contracts - **Solidity** on **Base** - Prediction logic, reward distribution, season lifecycle - Merkle root proof verification for claims ### ๐Ÿ“ฆ Off-Chain Infra | Layer | Tech | |------------------|-------------------------------| | League Snapshot | FPL API โ†’ JSON โ†’ IPFS | | Score Updates | Chainlink Functions โ†’ IPFS | | Automation | Chainlink Keepers | | Storage | IPFS (web3.storage, Pinata) | | Indexing | The Graph / Dune / Custom | ### ๐Ÿ“ฑ Farcaster Frame Frontend - **Frontend Framework**: Next.js - **UI**: TailwindCSS - **Wallet**: Farcaster-native (Privy, RainbowKit) - **Hosting**: IPFS + ENS domain, Vercel or Coolify. --- ## ๐Ÿ” Trust Minimization & Decentralization | Data | Secured By | |--------------------|------------------------| | League Snapshot | IPFS CID + Merkle root | | Scores | IPFS + Merkle (optional) | | Predictions | On-chain | | Claims | Merkle proof system | | Automation | Chainlink Keepers | | Frontend | Farcaster-native | --- ## ๐Ÿงญ Flow Summary 1. `startSeason(startGW, endGW)` - Snapshot league from FPL - Save manager list JSON to IPFS - Save Merkle root + CID on-chain 2. Users submit predictions on managers 3. Each Gameweek: - Scores fetched via Chainlink - Merkle tree generated - JSON uploaded to IPFS - Frontend renders current leaderboard from IPFS 4. `endSeason()` is called: - Scores from `startGW โ†’ endGW` computed - Final leaderboard saved to IPFS & Merkle root submitted - Top 3 managers finalized 5. Users & managers claim winnings using Merkle proofs --- ## ๐Ÿชช Access & Identity - **Farcaster** native - Only users with connected Farcaster ID can play - Frames used for seamless UX & walletless onboarding (Privy) --- ## ๐Ÿš€ Future Ideas - EXP / Level system for players based on wins - NFTs for predictions or manager cards - League-specific games (private or themed leagues) - Cook-off mode: Pick between two managers per Gameweek