# 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