This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a futarchy prediction market system built on Gnosis Chain, implementing decentralized governance mechanisms through token pairs and automated market makers. The system allows participants to trade on outcomes using conditional tokens split into YES/NO positions.
# Development
npm run dev # Start Next.js development server (http://localhost:3000)
# Build & Production
npm run build # Build for production
npm run start # Start production server
# Code Quality
npm run lint # Run Next.js linter
# Testing
npm test # No test command configured - use Cypress for E2E tests
npx cypress open # Open Cypress test runner
npx cypress run # Run Cypress tests headlessly
# Storybook
npm run storybook # Start Storybook dev server (http://localhost:6006)
npm run build-storybook # Build Storybook static site
# Utilities
npm run start-proposal # Run proposal CLI in interactive mode
npm run send-to-supabase # Send data to Supabase
npm run get-trade-history # Retrieve trade history from blockchain
npm run getpoolprice # Get current Algebra pool pricescd swapr/
# Interactive Operations
npm run interactive # Interactive mode wizard
npm run futarchy:create # Create new proposal
npm run view # View all positions
# Automated Pool Setup
npm run futarchy:auto futarchy-config.json # Automatic setup with config
npm run automate # Full workflow: config → generate → call APIs
npm run automate-dry # Preview full workflow (safe test)
# Pool API Operations
npm run generate-pools # Generate API files from latest setup
npm run call-pool-apis # Make ALL pool creation API calls
npm run call-pool-apis-dry # Preview API calls (safe test)
# Liquidity Management
npm run remove # Remove liquidity (interactive)
npm run merge <proposalAddr> # Merge conditional tokens back to collateral- Frontend: Next.js 14 with React 18 (pages router)
- Blockchain: Ethers.js v5 (main app), v6 (swapr CLI), Wagmi v2, RainbowKit
- Styling: Tailwind CSS, CSS Modules, PrimeReact components
- State Management: React Context API, TanStack Query
- Package Manager: pnpm v9.4.0
src/
├── pages/ # Next.js pages (routing)
├── components/ # React components
│ ├── futarchyFi/ # Main app components
│ └── refactor/ # New extensible swap system
├── hooks/ # Custom React hooks
├── contexts/ # React contexts
├── utils/ # Utility functions
├── providers/ # Web3 and app providers
└── futarchyJS/ # Core futarchy logic
swapr/ # Pool automation CLI tools
├── algebra-cli.js # Main CLI entry point
├── api-pool-create.js # Pool creation API client
└── futarchy-*.js # Futarchy-specific modules
-
Core Hook:
src/hooks/useFutarchy.js- Central hook managing all futarchy operations
- Handles swaps, positions, collateral, and balances
- Extensive callback system for UI updates
-
Web3 Integration:
src/contexts/Web3Context.js- MetaMask provider wrappersrc/providers/providers.jsx- Wagmi configuration with multi-RPC fallback
-
Swap Strategies:
src/components/refactor/strategies/- Extensible swap system using strategy pattern
- Support for Algebra/Swapr, CoW Swap protocols
- Factory pattern for strategy creation
-
Pool Automation:
swapr/algebra-cli.js- CLI tool for automated pool creation
- Supports both interactive and config-based operation
- Note: Uses ethers v6 (vs v5 in main app)
-
Strategy Pattern for Swaps
- Base classes:
BaseSwapStrategy.js,BaseRealtimeStrategy.js - Implementations:
AlgebraSwapStrategy.js,CowSwapStrategy.js - Factory:
SwapStrategyFactory.js
- Base classes:
-
RPC Resilience
- Multi-RPC fallback configuration in
providers.jsx - Custom retry logic in
utils/retryWithBackoff.js - RPC rotation in
utils/getAlgebraPoolPrice.js
- Multi-RPC fallback configuration in
-
Token Management
- Conditional tokens (YES/NO pairs)
- Automatic collateral management
- ERC20 approval handling with security measures
Key contracts are configured in:
src/futarchyJS/futarchyConfig.js- Main contract addressessrc/futarchyJS/contractWrapper.js- Contract imports and configssrc/components/refactor/constants/addresses.js- Refactored swap addresses
Required environment variables:
NEXT_PUBLIC_RPC_URL- Primary Gnosis Chain RPC URL (frontend)RPC_URL- RPC URL for backend/CLI tools- Additional API keys for external services (Supabase, etc.)
The app includes multi-RPC fallback for reliability:
// Default RPC endpoints (in order of priority)
- https://gnosis.drpc.org
- https://rpc.gnosischain.com
- https://rpc.ankr.com/gnosis
- https://gnosis-mainnet.public.blastapi.io
- https://gnosis-rpc.publicnode.com
- https://1rpc.io/gnosis- E2E Testing: Cypress (minimal coverage)
- Component Testing: Storybook for visual testing
- Unit Testing: No framework configured
- Smart Contract Testing: Hardhat tests in
index/test/
-
Adding a New Swap Protocol
- Create new strategy in
src/components/refactor/strategies/ - Extend
BaseSwapStrategyclass - Register in
SwapStrategyFactory
- Create new strategy in
-
Working with Hooks
- Place new hooks in
src/hooks/ - Follow callback pattern for UI updates
- Handle loading states and errors
- Place new hooks in
-
Blockchain Interactions
- Use ethers.js v5 in main app (NOT v6)
- Use ethers.js v6 in swapr CLI tools
- Implement proper gas estimation
- Handle transaction states comprehensively
The project uses GitHub Actions for CI/CD:
- Multiple staging environments (staging-1 through staging-5)
- Production deployment workflow
- Storybook deployment
- No test execution in CI (builds directly)
Deployments go to S3 with CloudFront CDN invalidation.
-
Token Approvals
- Reset allowances before setting new ones
- Use MaxUint256 for frequent operations
- Clear approval state tracking
-
RPC Security
- Multiple fallback RPCs for reliability
- Rate limiting protection
- Error handling for RPC failures
-
Transaction Safety
- Slippage protection on swaps
- Gas estimation with buffer
- Deadline enforcement