Inspiration

The explosion of prediction markets like Polymarket and Kalshi has shown that people love putting their money where their opinions are. However, building a platform that handles real financial transactions, dynamic pricing, and strict accounting is incredibly complex. We wanted to build a production-grade prediction market from scratch, but we didn't want to get bogged down in managing backend infrastructure. The "Zero Stack" hackathon was the perfect catalyst to combine the rapid UI generation of v0, the serverless edge deployment of Vercel, and the enterprise-grade reliability of AWS Databases to bring ForecastHub to life.

What it does

ForecastHub is a sophisticated prediction market platform where users trade on the outcomes of future events.

  • Dynamic AMM Pricing: Instead of a traditional order book, we use a Logarithmic Market Scoring Rule (LMSR) Automated Market Maker to dynamically calculate probabilities and prices based on trading volume.
  • Bank-Grade Accounting: We implemented a strict double-entry accounting ledger. Every deposit, trade, fee, and escrow lock is recorded as an atomic, balanced entry where the sum of all legs equals zero.
  • Wallet & Escrow System: Users have distinct "Cash" and "Escrow" accounts. Funds for active bets are locked in escrow, ensuring the platform always maintains 100% reserve backing for open positions.
  • Fiat On/Off Ramps: Integrated Stripe allows users to seamlessly deposit and withdraw real money.
  • Real-Time Analytics: Interactive Recharts-powered dashboards visualize historical price ticks and market liquidity in real time.

How we built it

We leveraged a bleeding-edge, modern tech stack to build a "Zero Stack" architecture:

  • Frontend & UI: Built with Next.js 16 (App Router) and React 19. We heavily utilized v0 to rapidly generate and iterate on complex, accessible UI components using Tailwind CSS 4 and shadcn/ui.
  • Database: We used Amazon RDS for PostgreSQL. To adhere to zero-trust security principles, we bypassed static passwords and implemented AWS IAM Database Authentication, generating short-lived auth tokens via the AWS SDK for every connection.
  • Backend Logic: The core business logic (LMSR math, double-entry ledger, and auth) is written in TypeScript and runs as Vercel Serverless Functions.
  • Payments: Integrated the Stripe API to handle fiat payment intents and process secure webhooks for deposit confirmations.
  • Security: Passwords are hashed using @node-rs/argon2, and we implemented timing-safe verification to prevent timing attacks.

Challenges we ran into

  • Financial Atomicity: Building a double-entry accounting system that guarantees data integrity was tough. We had to ensure that if a trade failed halfway through, the ledger, account balances, and market share counts would perfectly roll back without leaving "ghost" funds. We solved this by wrapping all financial operations in strict database transactions.
  • Serverless Database Connections: Connecting Vercel serverless functions to AWS RDS without exhausting connection limits or hardcoding credentials was a major hurdle. Implementing AWS IAM authentication and managing connection lifecycles in a serverless environment required careful engineering.
  • AMM Math & Precision: Implementing the LMSR pricing engine required handling complex exponential math. We had to carefully manage floating-point precision by storing prices in basis points (0-10,000) to prevent rounding errors that could be exploited in a financial system.

Accomplishments that we're proud of

  • Zero-Trust Security: Successfully implementing AWS IAM authentication for RDS. Our database has no static passwords; access is strictly controlled via AWS IAM roles and short-lived tokens.
  • Flawless Ledger: We are incredibly proud of our double-entry accounting engine. It enforces strict idempotency (preventing double-posting via unique keys) and guarantees that the platform's total liabilities always perfectly match user balances.
  • Rapid Development with v0: Using v0 allowed us to build a highly polished, dark-mode, financial-grade UI in a fraction of the time it would normally take, letting us focus our energy on the complex backend financial logic.
  • Bleeding-Edge Stack: Successfully deploying a highly complex financial application using the absolute latest versions of Next.js 16 and React 19.

What we learned

  • Financial Engineering: We gained a deep, practical understanding of how Automated Market Makers (AMMs) work under the hood, and why they are superior to traditional order books for low-liquidity prediction markets.
  • Cloud Security Best Practices: We learned how to properly configure AWS IAM policies for RDS and how to securely generate and inject authentication tokens in a serverless environment.
  • Serverless Architecture: We learned the nuances of handling stateful database transactions within stateless serverless functions, and the importance of atomic operations when dealing with user funds.

What's next for Forecasthub

  • Advanced Market Types: Expanding beyond binary (Yes/No) markets to include multi-choice outcomes and continuous numerical ranges.
  • AI-Driven Market Creation: Integrating Amazon Bedrock to automatically generate market descriptions, resolve ambiguous events using real-time news data, and detect anomalous trading behavior.
  • True Real-Time Multiplayer: Implementing WebSockets (via Vercel Edge or AWS API Gateway) to allow users to see each other's trades happening live on the order book.
  • High-Concurrency Scaling: Implementing Amazon RDS Proxy to better manage connection pooling and scale the database tier seamlessly during high-volume trading events.
Share this project:

Updates