{"id":48232774,"url":"https://github.com/cutupdev/evm-prediction-market-backend","last_synced_at":"2026-05-22T17:02:20.322Z","repository":{"id":300180783,"uuid":"1005412674","full_name":"cutupdev/EVM-Prediction-Market-Backend","owner":"cutupdev","description":"EVM prediction market backend, polymarket fork(clone)","archived":false,"fork":false,"pushed_at":"2026-03-27T20:16:26.000Z","size":6339,"stargazers_count":26,"open_issues_count":0,"forks_count":8,"subscribers_count":8,"default_branch":"main","last_synced_at":"2026-04-04T20:41:10.850Z","etag":null,"topics":["backend-services","evm","evm-blockchain","polymarket","prediction-markets"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cutupdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-06-20T07:31:27.000Z","updated_at":"2026-03-27T20:56:00.000Z","dependencies_parsed_at":"2025-06-20T09:40:03.972Z","dependency_job_id":null,"html_url":"https://github.com/cutupdev/EVM-Prediction-Market-Backend","commit_stats":null,"previous_names":["cutupdev/solana-blackjack-casino-game","cutupdev/evm-prediction-market-backend"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cutupdev/EVM-Prediction-Market-Backend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cutupdev%2FEVM-Prediction-Market-Backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cutupdev%2FEVM-Prediction-Market-Backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cutupdev%2FEVM-Prediction-Market-Backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cutupdev%2FEVM-Prediction-Market-Backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cutupdev","download_url":"https://codeload.github.com/cutupdev/EVM-Prediction-Market-Backend/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cutupdev%2FEVM-Prediction-Market-Backend/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33356136,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-21T12:23:38.849Z","status":"online","status_checked_at":"2026-05-22T02:00:06.671Z","response_time":265,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend-services","evm","evm-blockchain","polymarket","prediction-markets"],"created_at":"2026-04-04T19:45:34.103Z","updated_at":"2026-05-22T17:02:20.316Z","avatar_url":"https://github.com/cutupdev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EVM Prediction Market Backend\n\nNode.js **TypeScript** service for a prediction market on EVM chains: **JSON-RPC reads/writes**, **REST API** for a web UI, **PostgreSQL** via **Prisma**, an **off-chain central limit order book (CLOB)** with optional **EIP-712** signed orders, and **Socket.IO** for live order book and trade updates.\n\nThis repository is a **backend template**. You must align the Solidity ABI (`src/contracts/prediction-market.abi.ts`) and environment variables with your deployed contracts.\n\n## Architecture\n\n- **Chain layer** (`src/services/blockchain/`): `ethers` v6 `JsonRpcProvider`, read-only + optional operator wallet, calldata encoding for wallet-driven txs (`/api/v1/tx/*`), and a lightweight **log listener** that upserts `Market` rows and stores raw logs in `ChainEvent`.\n- **Order book** (`src/services/orderbook/`): in-memory **price–time priority** matching per `(marketId, outcomeIndex)`; **PostgreSQL** persists orders and trades. Suitable for a single API instance or a leader writer; for horizontal scale, add Redis or move matching behind a dedicated worker.\n- **UI integration**: CORS-enabled REST + `GET /api/v1/config/eip712` for typed-data signing; Socket.IO rooms `market:\u003cprismaMarketId\u003e` with events `orderbook:updated` and `trade`.\n\n## Prerequisites\n\n- Node.js 20+\n- PostgreSQL 14+\n\n## Setup\n\n1. Copy `.env.example` to `.env` and set `DATABASE_URL`, `RPC_URL`, `CHAIN_ID`, `PREDICTION_MARKET_ADDRESS`, and EIP-712 fields to match your deployment and frontend.\n\n2. Install dependencies and generate the Prisma client:\n\n   ```bash\n   npm install\n   npx prisma generate\n   npx prisma db push\n   ```\n\n3. Development:\n\n   ```bash\n   npm run dev\n   ```\n\n4. Production build:\n\n   ```bash\n   npm run build\n   npm start\n   ```\n\n## Environment\n\nSee `.env.example` for all variables. Important:\n\n| Variable | Role |\n|----------|------|\n| `DATABASE_URL` | PostgreSQL connection string |\n| `RPC_URL` | HTTPS JSON-RPC endpoint |\n| `CHAIN_ID` | Must match the chain id returned by the RPC |\n| `PREDICTION_MARKET_ADDRESS` | Core market contract |\n| `OPERATOR_PRIVATE_KEY` | Optional; only if the server submits transactions |\n| `CORS_ORIGINS` | Comma-separated browser origins |\n| `EIP712_*` | Must match the values used by your web app when signing orders |\n\n## HTTP API (summary)\n\nBase path: `API_PREFIX` (default `/api/v1`).\n\n| Method | Path | Description |\n|--------|------|-------------|\n| GET | `/health` | Liveness |\n| GET | `/api/v1/config/eip712` | EIP-712 domain and types for order signing |\n| GET | `/api/v1/markets` | List markets (`?resolved=true|false`, pagination) |\n| POST | `/api/v1/markets` | Register/upsert a market row (or rely on indexer) |\n| GET | `/api/v1/markets/:id` | Market by Prisma id |\n| GET | `/api/v1/markets/:id/chain` | DB row + on-chain `getMarket` snapshot |\n| GET | `/api/v1/markets/:id/orderbook?outcomeIndex=0` | Bids/asks snapshot |\n| POST | `/api/v1/markets/:id/orders` | Place order (optional `requireSignature: true`) |\n| GET | `/api/v1/markets/:id/trades` | Recent trades |\n| DELETE | `/api/v1/orders/:orderId?requester=0x…` | Cancel resting order |\n| GET | `/api/v1/users/:address/orders` | Orders for a wallet |\n| POST | `/api/v1/tx/buy` | Unsigned buy calldata for the user wallet |\n| POST | `/api/v1/tx/sell` | Unsigned sell calldata |\n| POST | `/api/v1/tx/claim` | Unsigned claim calldata |\n\n### Order placement body (example)\n\n```json\n{\n  \"makerAddress\": \"0x…\",\n  \"outcomeIndex\": 0,\n  \"side\": \"BUY\",\n  \"priceBps\": 5500,\n  \"sizeRaw\": \"1000000\",\n  \"requireSignature\": false\n}\n```\n\n`priceBps` is **basis points** of probability (1–10000). `sizeRaw` is an integer string in your collateral’s smallest units (convention must match the on-chain settlement path you implement).\n\nWith `requireSignature: true`, include `signature` and `chainNonce` matching `GET /api/v1/config/eip712` and `src/services/signing/eip712-order.ts`.\n\n### Socket.IO (browser / UI)\n\n```text\nconnect → emit(\"market:subscribe\", \"\u003cprismaMarketId\u003e\")\nlisten: \"orderbook:updated\" | \"trade\"\n```\n\n## Smart contract alignment\n\n1. Update `src/contracts/prediction-market.abi.ts` to match your contract.\n2. Ensure events `MarketCreated` / `MarketResolved` match if you use `event-indexer.service.ts`.\n3. Expose `getMarket(bytes32)` (or adjust `prediction-market.chain.ts`) so `/markets/:id/chain` stays accurate.\n\n## Contact Information\n\n- Telegram: https://t.me/DevCutup\n- Twitter: https://x.com/devcutup\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcutupdev%2Fevm-prediction-market-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcutupdev%2Fevm-prediction-market-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcutupdev%2Fevm-prediction-market-backend/lists"}