<<<<<<< HEAD
=======
DarkONNET is a privacy-preserving, automated prediction market built on the Zama fhEVM Sepolia Testnet. It leverages Fully Homomorphic Encryption (FHE) to keep user positions and market totals confidential while maintaining trustless, automated settlement.
- Smart contracts, faucet, deployment script, and oracle workers are implemented.
- Contract tests cover market admin actions, faucet minting/cooldown, encrypted betting, settlement claims, cancellation refunds, and two-phase early exits.
- Off-chain threaded market comments and real-time wallet notifications are available through the comments backend.
- The Next.js frontend application is built and integrated. It supports user wallet connection, market exploration, confidential betting via FHE, creator market requests, and a secure admin panel for creator market approval or resolving unresolved markets if there is any error.
- Token wrapping is planned but not implemented; current test liquidity comes from the confidential cUSDT faucet.
- Relayers read
INFURA_API_KEYandCONTRACT_ADDRESSfrom.env.
Traditional prediction markets (like Polymarket) are fully transparent. This leads to several issues:
- Copy-Trading: Large bettors can be tracked and copied.
- Market Manipulation: Visible pool totals allow whales to "swing" odds to their advantage.
- Privacy Leakage: A user's financial convictions are public knowledge.
DarkONNET solves this by using Zama's fhevm:
- Encrypted Bets: User bet amounts are stored as
euint64. - Private Liquidity: Total pool sizes are never revealed in plaintext until settlement.
- Confidential Payouts: Uses the Asynchronous Gateway Pattern to verify winnings and distribute payouts without ever exposing the math in the clear.
Foundr features a fully autonomous relayer suite that bridges real-world data into the FHE environment across 7 categories:
| Category | Data Provider | Logic |
|---|---|---|
| Esports | PandaScore API | Automatic match creation and winner settlement. |
| Sports | API-Sports | Covers Football (Premier League), NFL, and Formula 1. |
| Politics | NewsAPI (Reuters/AP) | Headlines-based settlement with consensus logic. |
| Tech | NewsAPI (TechCrunch/Verge) | Tracks product launches and tech milestones. |
| Crypto | CoinGecko API | Price-threshold markets (e.g., "BTC > $70k"). |
| Finance | NewsAPI (WSJ/Bloomberg) | Economic indicators and interest rate decisions. |
| Culture | NewsAPI (Variety) | Entertainment awards and cultural events. |
- Smart Contracts (
src/):ConfidentialPredictionMarket.sol: The core engine handling categorized markets and encrypted state.EncryptedERC20.sol: A custom cUSDT stablecoin.ConfidentialUSDTFaucet.sol: A rate-limited faucet for test liquidity.
- Relayers (
relayer/): 5 Node.js scripts that poll global APIs and triggercreateMarketandsettlefunctions on-chain. - Comments Backend (
backend/comments/): Stores off-chain, wallet-linked market commentary, threaded replies, market metadata, and real-time notifications. - Coprocessor: Utilizes Zama's KMS and Gateway for secure decryption of payout ratios.
- Foundry
- Node.js (v18+)
- Zama fhEVM Environment
Create a .env file with the following:
PRIVATE_KEY=your_wallet_private_key
INFURA_API_KEY=your_infura_api_key
ESPORTS_API_KEY=your_pandascore_key
NEWS_API_KEY=your_newsapi_key
SPORTS_API_KEY=your_apisports_key
CONTRACT_ADDRESS=0xYourDeployedPredictionMarketAddress
COMMENTS_PORT=8787
COMMENTS_DB_PATH=data/comments.json
API_AUTH_REQUIRED=true
API_ADMIN_WALLETS=0xYourAdminWallet
Deploy the entire ecosystem (Token, Faucet, Market) with one command:
./deploy.ps1Run your preferred oracle to start populating the market:
npm run oracle:cryptoStart the off-chain threaded comments backend:
npm run comments:devThe comments API supports:
GET /api/markets/:marketId/commentsPOST /api/markets/:marketId/commentsGET /api/marketsGET /api/markets/:marketIdPUT /api/markets/:marketIdPOST /api/markets/:marketId/participantsGET /api/wallets/:walletAddress/notificationsPATCH /api/wallets/:walletAddress/notifications/:notificationIdPOST /api/wallets/:walletAddress/notificationsGET /api/wallets/:walletAddress/profilePUT /api/wallets/:walletAddress/profileWS /ws/notifications?walletAddress=:walletAddress
Mutating routes and wallet notification feeds require signed wallet authentication when API_AUTH_REQUIRED is not set to false.
Clients sign this message shape with their wallet:
DarkONNET API request
Wallet: 0x...
Method: POST
Path: /api/markets/123/comments
Timestamp: 1770000000000
BodyHash: 0x...
Creator submissions must be signed by creatorWalletAddress. Comment, participant, profile, and notification actions must be signed by the target wallet. Admin/oracle metadata writes, market acceptance, decline, and resolution must be signed by a wallet listed in API_ADMIN_WALLETS.
Create a comment or reply with:
{
"walletAddress": "0x1111111111111111111111111111111111111111",
"displayName": "Alice",
"body": "This market is heating up.",
"parentId": "optional-existing-comment-id"
}Market metadata is written by the relayers after on-chain market creation. The frontend can use it for market cards:
{
"marketId": "123",
"onchainMarketId": "123",
"slug": "arsenal-vs-chelsea",
"category": "Sports - Football",
"title": "Arsenal vs Chelsea",
"homeLogoUrl": "https://media.api-sports.io/football/teams/42.png",
"awayLogoUrl": "https://media.api-sports.io/football/teams/49.png",
"imageUrl": "https://example.com/article-or-league-image.png",
"creatorWalletAddress": "0x1111111111111111111111111111111111111111",
"status": "pending"
}Notifications are stored by wallet address and pushed live to connected clients. Connect with:
ws://localhost:8787/ws/notifications?walletAddress=0x1111111111111111111111111111111111111111
The server creates notifications when:
- someone replies to a user's comment;
- a creator's market transitions to
status: "accepted"; - a market transitions to
status: "resolved"for wallets registered throughPOST /api/markets/:marketId/participants.
Live notification messages are JSON:
{
"type": "notification.created",
"notification": {
"type": "market.resolved",
"marketId": "123",
"title": "Market resolved",
"body": "A market you participated in was resolved: Arsenal vs Chelsea"
}
}- Prediction Market:
0x0dbeA55D54647759dC7eA6523d005B3c9C173730 - cUSDT Token:
0x3f14f7f11131E4698ED5Ad6A03C3EF1924cF3F0d - Faucet:
0xd978f57d7fD0fAb73a99D7D68c962386F25E1D00
MIT - Built for the Zama dApp Demo Challenge.
c42f364 (initial commit: DarkONNET backend, oracles, and smart contracts)