80 lines
3.1 KiB
Markdown
80 lines
3.1 KiB
Markdown
# PollCelo Mini-App Walkthrough
|
|
|
|
## Overview
|
|
PollCelo is a Farcaster Mini-App that allows users to create and vote on daily polls. It features:
|
|
- **Poll Creation**: Users pay 5 cUSD (on Celo) to create a poll.
|
|
- **Real-time Rates**: Fetches USD/TRY rates from DexScreener for prediction polls.
|
|
- **Automated Verification**: Verifies poll results using external APIs (e.g., checking if the rate hit a target).
|
|
- **Prize Distribution**: Automatically distributes the pot to winners via cron jobs.
|
|
|
|
## Features Implemented
|
|
|
|
### 1. Database & Backend
|
|
- **Neon PostgreSQL**: Stores polls, options, votes, and distributions.
|
|
- **Drizzle ORM**: Type-safe database interactions.
|
|
- **Hono API**:
|
|
- `GET /api/poll`: Fetch active polls.
|
|
- `POST /api/vote`: Record votes.
|
|
- `POST /api/create-poll`: Create new polls with payment validation.
|
|
- `GET /api/rates`: Real-time cUSD and USD/TRY rates.
|
|
- `GET /api/cron/verify`: Cron job to verify ended polls.
|
|
- `GET /api/cron/distribute`: Cron job to distribute prizes.
|
|
|
|
### 2. Frontend
|
|
- **React + Vite**: Fast and responsive UI.
|
|
- **Wagmi + Viem**: Wallet connection and transaction handling (Celo Alfajores).
|
|
- **Pages**:
|
|
- **Home**: View active poll, vote, and see real-time rates.
|
|
- **Create Poll**: Form to create a new poll with a 5 cUSD fee.
|
|
|
|
### 3. Automation
|
|
- **Verification Logic**: Checks external data sources to validate poll outcomes.
|
|
- **Distribution Logic**: Calculates winners and sends payments from the protocol wallet.
|
|
|
|
## How to Test
|
|
|
|
### Prerequisites
|
|
1. **Environment Variables**: Ensure `.dev.vars` in `backend/` has:
|
|
- `DATABASE_URL`: Your Neon DB connection string.
|
|
- `PROTOCOL_PRIVATE_KEY`: Private key for the protocol wallet (for distribution).
|
|
2. **Dependencies**: Run `pnpm install` in both `frontend` and `backend`.
|
|
|
|
### Running Locally
|
|
1. **Start Backend**:
|
|
```bash
|
|
cd backend
|
|
pnpm dev
|
|
```
|
|
Runs on `http://localhost:8787` (or similar port).
|
|
|
|
2. **Start Frontend**:
|
|
```bash
|
|
cd frontend
|
|
pnpm dev
|
|
```
|
|
Runs on `http://localhost:5173`.
|
|
|
|
### End-to-End Flow
|
|
1. **Connect Wallet**: Open the frontend and connect your wallet (Celo Alfajores).
|
|
2. **Create Poll**:
|
|
- Click the "+" button.
|
|
- Enter a question (e.g., "Will USD/TRY > 35?").
|
|
- Enter options (e.g., "Yes", "No").
|
|
- Select "External API" verification.
|
|
- Click "Pay 5 cUSD & Create".
|
|
- Approve the transaction in your wallet.
|
|
3. **Vote**:
|
|
- Go back to Home.
|
|
- See your new poll.
|
|
- Click an option to vote (Note: Voting requires `POST /api/vote` integration with wallet signature, currently mocked in UI).
|
|
4. **Verification (Simulated)**:
|
|
- Manually trigger the cron: `curl http://localhost:8787/api/cron/verify`.
|
|
- If the poll has ended (you might need to adjust `endTime` in DB for testing), it will be verified.
|
|
5. **Distribution (Simulated)**:
|
|
- Manually trigger the cron: `curl http://localhost:8787/api/cron/distribute`.
|
|
- Winners will receive their share.
|
|
|
|
## Deployment
|
|
1. **Backend**: `cd backend && pnpm run deploy` (Deploys to Cloudflare Workers).
|
|
2. **Frontend**: Build with `pnpm build` and deploy to Vercel/Netlify (configure proxy or update API URL).
|