celo-poll/SPORTS_POLLS_GUIDE.md
2025-12-08 16:31:30 +03:00

396 lines
8.9 KiB
Markdown

# 🏈 Sports Polls Guide - ESPN Integration
PollCelo now has **native ESPN integration** for automatic sports score verification! No API key needed.
## Supported Sports
### American Football
- βœ… **NFL** - All games
- βœ… **College Football** - All conferences
### Basketball
- βœ… **NBA** - All games
- βœ… **WNBA** - All games
- βœ… **Men's College Basketball** - All divisions
- βœ… **Women's College Basketball** - All divisions
### Baseball
- βœ… **MLB** - All games
- βœ… **College Baseball** - All divisions
### Hockey
- βœ… **NHL** - All games
### Soccer
- βœ… **English Premier League** (EPL)
- βœ… **La Liga** (Spain)
- βœ… **Bundesliga** (Germany)
- βœ… **Serie A** (Italy)
- βœ… **Ligue 1** (France)
- βœ… **MLS** (USA)
- βœ… **Champions League**
- βœ… **World Cup**
## Quick Start Examples
### Example 1: NFL Game Winner
```typescript
import { createPoll } from '@/lib/db/polls'
const poll = await createPoll({
creatorFid: 123,
creatorAddress: '0x...',
question: 'Chiefs vs Bills - Who wins?',
emoji: '🏈',
options: [
{ text: 'Chiefs', emoji: 'πŸ”΄' },
{ text: 'Bills', emoji: 'πŸ”΅' },
{ text: 'Draw', emoji: '🀝' },
],
startTime: Date.now(),
endTime: Date.now() + 4 * 60 * 60 * 1000, // 4 hours (game time)
status: 'active',
verificationType: 'espn',
verificationConfig: {
sport: 'football/nfl',
homeTeam: 'Kansas City Chiefs',
awayTeam: 'Buffalo Bills',
date: '20250126', // YYYYMMDD
comparisonType: 'home_wins',
},
creationFee: 5,
})
```
### Example 2: NBA Over/Under
```typescript
const poll = await createPoll({
creatorFid: 123,
creatorAddress: '0x...',
question: 'Lakers vs Warriors - Over/Under 220 total points?',
emoji: 'πŸ€',
options: [
{ text: 'Over 220', emoji: '⬆️' },
{ text: 'Under 220', emoji: '⬇️' },
],
startTime: Date.now(),
endTime: Date.now() + 3 * 60 * 60 * 1000,
status: 'active',
verificationType: 'espn',
verificationConfig: {
sport: 'basketball/nba',
homeTeam: 'Los Angeles Lakers',
awayTeam: 'Golden State Warriors',
comparisonType: 'over_under',
targetScore: 220,
},
creationFee: 5,
})
```
### Example 3: EPL Soccer Match
```typescript
const poll = await createPoll({
creatorFid: 123,
creatorAddress: '0x...',
question: 'Man City vs Liverpool - Winner?',
emoji: '⚽',
options: [
{ text: 'Man City', emoji: 'πŸ”΅' },
{ text: 'Liverpool', emoji: 'πŸ”΄' },
{ text: 'Draw', emoji: '🀝' },
],
startTime: Date.now(),
endTime: Date.now() + 2 * 60 * 60 * 1000,
status: 'active',
verificationType: 'espn',
verificationConfig: {
sport: 'soccer',
league: 'eng.1', // EPL
homeTeam: 'Manchester City',
awayTeam: 'Liverpool',
},
creationFee: 5,
})
```
### Example 4: Using Game ID
```typescript
const poll = await createPoll({
creatorFid: 123,
creatorAddress: '0x...',
question: 'Super Bowl LVIII - Winner?',
emoji: 'πŸ†',
options: [
{ text: 'AFC Champion', emoji: '🏈' },
{ text: 'NFC Champion', emoji: '⚑' },
],
startTime: Date.now(),
endTime: Date.now() + 5 * 60 * 60 * 1000,
status: 'active',
verificationType: 'espn',
verificationConfig: {
sport: 'football/nfl',
gameId: '401547438', // Specific ESPN game ID
},
creationFee: 5,
})
```
## Verification Config Options
### Required Fields
- `sport` - Sport type (see list below)
- One of:
- `gameId` - ESPN game ID (if known)
- `homeTeam` + `awayTeam` - Team names (will find game)
### Optional Fields
- `league` - For soccer only (e.g., 'eng.1' for EPL)
- `date` - Game date in YYYYMMDD format
- `comparisonType` - How to determine winner:
- `'home_wins'` - Home team wins (default)
- `'away_wins'` - Away team wins
- `'draw'` - Match ends in draw
- `'over_under'` - Total score comparison
- `'exact_score'` - Specific score prediction
- `targetScore` - For over/under bets
## Sport Types
### Football
- `'football/nfl'` - NFL
- `'football/college-football'` - College Football
### Basketball
- `'basketball/nba'` - NBA
- `'basketball/wnba'` - WNBA
- `'basketball/mens-college-basketball'` - Men's College
- `'basketball/womens-college-basketball'` - Women's College
### Baseball
- `'baseball/mlb'` - MLB
- `'baseball/college-baseball'` - College Baseball
### Hockey
- `'hockey/nhl'` - NHL
### Soccer
- `'soccer'` - Soccer (requires `league` parameter)
## Soccer Leagues
- `'eng.1'` - English Premier League
- `'esp.1'` - La Liga (Spain)
- `'ger.1'` - Bundesliga (Germany)
- `'ita.1'` - Serie A (Italy)
- `'fra.1'` - Ligue 1 (France)
- `'usa.1'` - MLS (USA)
- `'uefa.champions'` - UEFA Champions League
- `'fifa.world'` - FIFA World Cup
## How Verification Works
### 1. Poll Ends
- Poll `endTime` passes
- Status changes to `'closed'`
### 2. Cron Job Runs
- Verification cron runs every hour at :00
- Finds closed ESPN polls
### 3. ESPN API Call
- Fetches game data from ESPN
- Checks if game is completed
- Gets final scores
### 4. Determine Winner
- Based on `comparisonType`:
- Winner: Compares scores
- Over/Under: Sums total scores
- Draw: Checks if scores equal
### 5. Mark Verified
- Sets `correct_option_id`
- Stores proof data
- Status β†’ `'verified'`
### 6. Distribution
- 15 minutes later, distribution cron runs
- Pays all winners automatically
## Best Practices
### 1. Set Proper End Time
```typescript
// NFL game starts at 1 PM, lasts ~3 hours
const gameStart = new Date('2025-01-26T13:00:00')
const endTime = gameStart.getTime() + (4 * 60 * 60 * 1000) // 4 hours buffer
```
### 2. Use Correct Team Names
```typescript
// βœ… Good - Full official name
homeTeam: 'Kansas City Chiefs'
// ❌ Bad - Abbreviation might not match
homeTeam: 'KC'
// βœ… Also works - City name
homeTeam: 'Kansas City'
```
### 3. Add Buffer Time
```typescript
// Game ends around 4 PM, add 1 hour buffer
endTime: gameEndTime + (60 * 60 * 1000)
```
### 4. Use League for Soccer
```typescript
// βœ… Correct
verificationType: 'espn',
verificationConfig: {
sport: 'soccer',
league: 'eng.1',
homeTeam: 'Manchester City',
awayTeam: 'Liverpool',
}
// ❌ Wrong - missing league
verificationConfig: {
sport: 'soccer',
homeTeam: 'Manchester City',
}
```
## Testing
### Test with Completed Game
```typescript
// Use a game that already happened
const poll = await createPoll({
question: 'Test: Who won Super Bowl LVII?',
endTime: Date.now() - 1000, // Already ended
verificationType: 'espn',
verificationConfig: {
sport: 'football/nfl',
gameId: '401437937', // Super Bowl LVII
},
})
// Manually trigger verification
// curl -H "Authorization: Bearer YOUR_CRON_SECRET" \
// http://localhost:3000/api/cron/verify
```
## Error Handling
### Game Not Found
- Check team names are correct
- Verify date format (YYYYMMDD)
- Try using gameId instead
### Game Not Completed
- Poll ended before game finished
- Verification will retry next hour
- Game might be postponed
### Invalid Sport
- Check sport type spelling
- Verify league code for soccer
- See supported sports list above
## Advanced Examples
### College Football Rivalry
```typescript
{
question: 'Iron Bowl: Alabama vs Auburn - Winner?',
verificationType: 'espn',
verificationConfig: {
sport: 'football/college-football',
homeTeam: 'Auburn',
awayTeam: 'Alabama',
date: '20251125',
},
}
```
### Champions League
```typescript
{
question: 'Real Madrid vs Barcelona - El ClΓ‘sico Winner?',
verificationType: 'espn',
verificationConfig: {
sport: 'soccer',
league: 'uefa.champions',
homeTeam: 'Real Madrid',
awayTeam: 'Barcelona',
},
}
```
### NHL Playoffs
```typescript
{
question: 'Stanley Cup Finals Game 7 - Winner?',
verificationType: 'espn',
verificationConfig: {
sport: 'hockey/nhl',
homeTeam: 'Colorado Avalanche',
awayTeam: 'Tampa Bay Lightning',
},
}
```
## Troubleshooting
### "Game not found"
1. Check ESPN scoreboard for the day:
```
http://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard?dates=20250126
```
2. Verify team names match ESPN's data
3. Try using gameId from ESPN URL
### "Game not completed yet"
- Poll ended too early
- Wait for next verification cron run
- Game might be in overtime
### Verification keeps failing
1. Check `verification_attempts` table for errors
2. Test ESPN API manually
3. Verify team names and sport type
## FAQ
**Q: Can I create polls for future games?**
A: Yes! Set `endTime` to after the game completes.
**Q: What if a game is postponed?**
A: Verification will fail until game is played. Consider refund policy.
**Q: Do I need an ESPN API key?**
A: No! ESPN's endpoints are public (for now).
**Q: Can I use this for international sports?**
A: Yes! Soccer leagues from around the world are supported.
**Q: What about college sports?**
A: Full support for college football and basketball!
**Q: How accurate is the timing?**
A: Verification runs hourly. Games update in ESPN API immediately after completion.
---
**Ready to create sports polls?** ESPN integration is fully automated - just set it up and let the system handle everything! πŸ†