|
| 1 | +# OpenSVM P2P Exchange - Copilot Instructions |
| 2 | + |
| 3 | +OpenSVM P2P Exchange is a Next.js-based Progressive Web App (PWA) for peer-to-peer cryptocurrency trading across Solana Virtual Machine networks (Solana, Sonic, Eclipse, svmBNB, s00n). The platform includes a React 19.1.1 frontend, Solana smart contracts built with Anchor 0.31.1, and comprehensive testing infrastructure. |
| 4 | + |
| 5 | +**ALWAYS reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.** |
| 6 | + |
| 7 | +## Working Effectively |
| 8 | + |
| 9 | +### Prerequisites and System Setup |
| 10 | +**Install required system dependencies first:** |
| 11 | +```bash |
| 12 | +sudo apt-get update && sudo apt-get install -y libudev-dev libssl-dev pkg-config build-essential |
| 13 | +``` |
| 14 | + |
| 15 | +### Bootstrap and Build Process |
| 16 | +**Follow these steps in exact order:** |
| 17 | + |
| 18 | +1. **Install Dependencies** (NEVER CANCEL - takes up to 90 seconds): |
| 19 | + ```bash |
| 20 | + npm install --legacy-peer-deps |
| 21 | + ``` |
| 22 | + - CRITICAL: Must use `--legacy-peer-deps` flag due to React 19.1.1 peer dependency conflicts |
| 23 | + - Takes ~47 seconds, set timeout to 120+ seconds minimum |
| 24 | + - Will show deprecation warnings - this is normal |
| 25 | + |
| 26 | +2. **Build Application** (NEVER CANCEL - takes up to 60 minutes): |
| 27 | + ```bash |
| 28 | + npm run build |
| 29 | + ``` |
| 30 | + - Takes ~31 seconds for clean build, but can take much longer with complex dependencies |
| 31 | + - Set timeout to 3600+ seconds (60+ minutes) minimum |
| 32 | + - Creates optimized production build in `build/` directory |
| 33 | + |
| 34 | +3. **Install Solana Development Tools** (NEVER CANCEL - takes up to 180 seconds): |
| 35 | + ```bash |
| 36 | + # Install Anchor Version Manager |
| 37 | + cargo install --git https://github.com/coral-xyz/anchor avm --locked --force |
| 38 | + # Add to PATH (critical step) |
| 39 | + echo 'export PATH="$HOME/.avm/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc |
| 40 | + # Install and use Anchor 0.31.1 |
| 41 | + avm install 0.31.1 && avm use 0.31.1 |
| 42 | + ``` |
| 43 | + - AVM installation takes ~77 seconds plus system dependency installation |
| 44 | + - Set timeout to 300+ seconds minimum |
| 45 | + - PATH configuration is critical for Anchor commands to work |
| 46 | + |
| 47 | +4. **Build Solana Program** (NEVER CANCEL - takes up to 60 seconds): |
| 48 | + ```bash |
| 49 | + cd programs/p2p-exchange && cargo check |
| 50 | + ``` |
| 51 | + - Takes ~28 seconds for compilation check |
| 52 | + - Set timeout to 120+ seconds minimum |
| 53 | + - Will show warnings about deprecated modules - this is expected |
| 54 | + - Returns to repository root: `cd ../..` |
| 55 | + |
| 56 | +### Development Workflow |
| 57 | + |
| 58 | +1. **Start Development Server:** |
| 59 | + ```bash |
| 60 | + npm run dev |
| 61 | + ``` |
| 62 | + - Starts in ~1.2 seconds |
| 63 | + - Available at http://localhost:3000 |
| 64 | + - Includes hot reloading and React DevTools |
| 65 | + |
| 66 | +2. **Run Tests** (NEVER CANCEL - takes up to 45 minutes): |
| 67 | + ```bash |
| 68 | + npm test |
| 69 | + ``` |
| 70 | + - Takes ~31 seconds but some tests fail due to missing API mocks |
| 71 | + - Set timeout to 2700+ seconds (45+ minutes) minimum |
| 72 | + - Known failures: Solana TextEncoder issues, missing API modules |
| 73 | + - Test failures are expected in current state |
| 74 | + |
| 75 | +3. **Lint Code:** |
| 76 | + ```bash |
| 77 | + npm run lint |
| 78 | + ``` |
| 79 | + - Takes ~5 seconds |
| 80 | + - Known issue: Parse error in `src/components/profile/ProfileSettings_backup.js` |
| 81 | + - Shows React Hooks warnings - these are non-blocking |
| 82 | + |
| 83 | +4. **Run E2E Tests:** |
| 84 | + ```bash |
| 85 | + npm run test:e2e |
| 86 | + ``` |
| 87 | + - Takes ~4 seconds in CI mode |
| 88 | + - Automatically kills development server on port 3000 |
| 89 | + - Uses external server configuration |
| 90 | + |
| 91 | +### Production Deployment |
| 92 | +```bash |
| 93 | +npm run build && npm run start |
| 94 | +``` |
| 95 | +- Must build first before starting production server |
| 96 | +- Production server starts instantly once build exists |
| 97 | + |
| 98 | +## Validation Requirements |
| 99 | + |
| 100 | +**ALWAYS run through this complete validation scenario after making changes:** |
| 101 | + |
| 102 | +1. **Start Development Server:** |
| 103 | + ```bash |
| 104 | + npm run dev |
| 105 | + ``` |
| 106 | + |
| 107 | +2. **Manual UI Validation:** |
| 108 | + - Navigate to http://localhost:3000 |
| 109 | + - Verify page loads with title "OpenSVM P2P Exchange" |
| 110 | + - Check navigation elements present: BUY, SELL, ANALYTICS, HELP, PROFILE |
| 111 | + - Confirm theme selector shows current theme |
| 112 | + - Verify network selector shows "Solana" |
| 113 | + - Check language selector shows "🇺🇸 EN" |
| 114 | + - Verify wallet connect button shows "CONNECT PHANTOM" |
| 115 | + - Confirm main content area loads (may show "Loading..." initially) |
| 116 | + |
| 117 | +3. **PWA Functionality Check:** |
| 118 | + - Open browser console |
| 119 | + - Verify "Service Worker registered successfully" message appears |
| 120 | + - Confirm no critical JavaScript errors |
| 121 | + |
| 122 | +4. **Build Validation:** |
| 123 | + ```bash |
| 124 | + npm run build |
| 125 | + ``` |
| 126 | + - Must complete without errors |
| 127 | + - Verify static export completes successfully |
| 128 | + |
| 129 | +5. **Solana Program Validation:** |
| 130 | + ```bash |
| 131 | + cd programs/p2p-exchange && cargo check && cd ../.. |
| 132 | + ``` |
| 133 | + - Must compile successfully (warnings are acceptable) |
| 134 | + |
| 135 | +## Common Tasks and Outputs |
| 136 | + |
| 137 | +### Repository Structure |
| 138 | +``` |
| 139 | +. |
| 140 | +├── README.md |
| 141 | +├── package.json # Dependencies and scripts |
| 142 | +├── next.config.js # Next.js PWA configuration |
| 143 | +├── Anchor.toml # Solana program configuration |
| 144 | +├── programs/p2p-exchange/ # Rust smart contracts |
| 145 | +├── src/ # React frontend source |
| 146 | +├── public/ # Static assets |
| 147 | +├── scripts/ # Build and test scripts |
| 148 | +├── tests/ # Comprehensive test suites |
| 149 | +├── docs/ # API and developer documentation |
| 150 | +└── .github/workflows/ # CI/CD pipelines |
| 151 | +``` |
| 152 | + |
| 153 | +### Key Package.json Scripts |
| 154 | +```bash |
| 155 | +npm run dev # Development server |
| 156 | +npm run build # Production build |
| 157 | +npm run start # Production server |
| 158 | +npm run lint # ESLint checking |
| 159 | +npm test # Jest unit tests |
| 160 | +npm run test:e2e # Puppeteer E2E tests |
| 161 | +npm run test:comprehensive # Full test suite (requires Solana validator) |
| 162 | +npm run performance # Bundle analysis |
| 163 | +``` |
| 164 | + |
| 165 | +### Anchor Configuration (Anchor.toml) |
| 166 | +- Program ID: `ASU1Gjmx9XMwErZumic9DNTADYzKphtEd1Zy4BFwSpnk` |
| 167 | +- Target: Solana devnet |
| 168 | +- Anchor version: 0.31.1 |
| 169 | +- Cluster: devnet by default |
| 170 | + |
| 171 | +## Critical Warnings and Timeouts |
| 172 | + |
| 173 | +### Build Commands - NEVER CANCEL |
| 174 | +- **npm install**: Set timeout to 120+ seconds (observed: 47s) |
| 175 | +- **npm run build**: Set timeout to 3600+ seconds (observed: 31s, but can take 45+ minutes) |
| 176 | +- **npm test**: Set timeout to 2700+ seconds (observed: 31s, but can take 45+ minutes) |
| 177 | +- **cargo install avm**: Set timeout to 300+ seconds (observed: 77s + deps) |
| 178 | +- **cargo check**: Set timeout to 120+ seconds (observed: 28s) |
| 179 | + |
| 180 | +### Known Issues to Document |
| 181 | +- Linting fails on `ProfileSettings_backup.js` with parse error |
| 182 | +- Some unit tests fail due to missing Solana TextEncoder polyfills |
| 183 | +- Comprehensive test suite requires local Solana validator |
| 184 | +- Must use `--legacy-peer-deps` flag for npm install |
| 185 | +- System dependencies required for Anchor installation |
| 186 | + |
| 187 | +## Technology Stack |
| 188 | + |
| 189 | +### Frontend |
| 190 | +- **Next.js 15.4.6**: React framework with SSR and static export |
| 191 | +- **React 19.1.1**: UI library with latest hooks |
| 192 | +- **Progressive Web App**: Service workers, offline functionality, installable |
| 193 | +- **Responsive Design**: Mobile-first with Tailwind CSS 4.1.10 |
| 194 | +- **Wallet Integration**: Phantom, Solflare, and other Solana wallets |
| 195 | + |
| 196 | +### Smart Contracts |
| 197 | +- **Solana/Anchor 0.31.1**: Rust-based smart contract framework |
| 198 | +- **Rust 1.88.0+**: Systems programming language |
| 199 | +- **Program ID**: ASU1Gjmx9XMwErZumic9DNTADYzKphtEd1Zy4BFwSpnk |
| 200 | + |
| 201 | +### Testing |
| 202 | +- **Jest 30.0.0**: Unit testing framework |
| 203 | +- **Puppeteer 24.10.0**: E2E testing with browser automation |
| 204 | +- **Comprehensive Test Suite**: Security, unit, integration, and performance tests |
| 205 | + |
| 206 | +### Build Tools |
| 207 | +- **Webpack 5.99.9**: Module bundler with blockchain polyfills |
| 208 | +- **Babel**: JavaScript transpilation with custom configuration |
| 209 | +- **ESLint**: Code linting with Next.js configuration |
| 210 | + |
| 211 | +## Network Configuration |
| 212 | +- **Primary Network**: Solana Devnet |
| 213 | +- **Supported Networks**: Solana, Sonic, Eclipse, svmBNB, s00n |
| 214 | +- **RPC Endpoint**: https://api.devnet.solana.com (default) |
| 215 | +- **Explorer**: https://explorer.solana.com/?cluster=devnet |
| 216 | + |
| 217 | +## Development Environment Requirements |
| 218 | +- **Node.js**: 18.17.0 or higher (validated with 20.19.4) |
| 219 | +- **npm**: 7.0.0 or higher |
| 220 | +- **Rust**: Latest stable (validated with 1.88.0) |
| 221 | +- **System**: Linux/macOS/Windows with build tools |
| 222 | +- **Memory**: 4GB minimum, 8GB recommended |
| 223 | +- **Storage**: 1GB+ free space |
| 224 | + |
| 225 | +This codebase is actively developed with comprehensive testing and deployment automation. Always validate changes through the complete manual scenario before committing. |
0 commit comments