How eshan-sharma/chainpot works
Project type and purpose
• This is a full-stack decentralized application (“dApp”) combining a modern web front end (Next.js + TailwindCSS), a TypeScript/Node.js back end (Next.js API routes + tRPC + Prisma + PostgreSQL), and a suite of Solidity smart contracts (built with Foundry).
• Purpose: Users deposit into escrow, earn yield via Compound v3, and compete in an auction or lottery (Pyth Oracle randomness) to claim the yield. Access is invite-only and governed by on-chain modules.
File structure
• Top-level folders:
• prisma/ (database schema for InviteCode, User, Pool, etc.)
• smart-contract/ (Foundry project, modules: Escrow, Auction Engine, Lottery Engine, Member Account Manager, Compound Integrator)
• src/ (Next.js application)
– src/app (React pages, Layout, API routes for NextAuth & tRPC)
– src/server (tRPC routers, auth config, Prisma client)
– src/trpc (client hooks)
• Config/build files: next.config.js, tsconfig.json, start-database.sh
• Smart-contract sub-folders for tests, scripts, and forge configuration.
README for additional insights
• Features list clarifying on-chain modules and off-chain services
• Tech-stack table highlights key frameworks (Foundry, Compound v3, Pyth Entropy, NextAuth/Reclaim, Wagmi/RainbowKit).
a. Main components:
• User & Wallet (RainbowKit + Wagmi)
• Frontend (Next.js + TailwindCSS)
• Authentication layer (NextAuth + Reclaim Protocol)
• API & Business logic (tRPC routers in Next.js API routes)
• Database (Prisma → PostgreSQL)
• Smart Contracts (Escrow, Member Manager, Auction Engine, Lottery Engine, Compound Integrator)
• External services (Compound v3, Pyth Entropy Oracle)
• Blockchain network (Ethereum or testnet)
b. Relationships & interactions:
1. User connects wallet via RainbowKit/Wagmi → interacts directly with smart contracts for deposits/withdrawals.
2. Frontend calls NextAuth endpoints to sign in/up off-chain.
3. Frontend uses tRPC client to fetch pool/user data and invite codes from the backend.
4. Backend (tRPC routers) reads/writes via Prisma to PostgreSQL.
5. Backend monitors contract events (e.g., cycle end) and may trigger on-chain transactions (e.g., reset, award yield).
6. Smart contracts call out to Compound v3 for yield and to Pyth Oracle for randomness.
c. Architectural patterns & design principles:
• Separation of concerns: UI vs. backend API vs. on-chain
• Modular smart contracts: one contract per domain (Escrow, Auction, Lottery, Member)
• Event-driven flow: backend reacts to blockchain events
• Type-safe client-server communication via tRPC
d. Key technologies/frameworks:
• Frontend: Next.js, TailwindCSS, Wagmi, RainbowKit
• Auth: NextAuth, Reclaim Protocol
• API: Next.js API routes + tRPC
• DB: Prisma ORM + PostgreSQL
• Smart contracts: Solidity (Foundry)
• Yield: Compound v3
• Randomness: Pyth Entropy
Elements
• Clear labels for each component (e.g., “NextAuth,” “tRPC Router: post.ts,” “Prisma Client,” “Escrow Contract”)
• Gray hexagons for smart contracts
Detail without over-splitting
• Prisma model’s role (InviteCode, User, Pool) as part of the DB layer.
• How Foundry tests/scripts fit into the smart-contract CI pipeline (optional annotation).
• Event listeners in the server that react to on-chain events.