How ownprotocol/own-smart-contracts works
Project Type and Purpose
• This is a blockchain dApp—a full‐stack project combining:
– A Next.js (T3 stack) client (“client/”)
– A Hardhat smart‐contract project (“contracts/”)
– Serverless API routes for signing presale arguments and user auth
• Purpose:
– Let users buy a token in a presale, stake it, and earn rewards on a testnet (Sepolia).
File Structure for Components
Frontend (“client/”)
• Framework: Next.js with React (app directory, pages, components)
• State & Data Fetch: React Query (providers, hooks), custom hooks (use-staking, use-presale, etc.)
• API layer: Next.js Route Handlers under src/app/api for:
– /api/contracts/get-signed-presale-args
– /api/users/auth/get-user
• UI Components: organized by feature (home, presale, staking, tokenomics, user-stake)
• Config & Providers: thirdweb client, chain‐connect provider, network‐switch, query‐client
Smart Contracts (“contracts/”)
• Hardhat project with Solidity contracts for OWN token, presale, staking, veOwn
• Deployment scripts (deploy/001_… to 005_…)
• Tests by feature (presale, stake, veOwn)
• Config: .env, hardhat.config.ts, .openzeppelin for network deployments
Shared / External
• Blockchain network: Sepolia testnet RPC
• Third-party services:
– thirdweb (contract abstraction + wallet connection)
– Wert (fiat-on-ramp)
– Sablier (planned vesting)
README for Architecture Clues
• Confirms two subprojects (client, contracts) and tech stacks (Bun, Vercel/pnpm)
• Notes on staking logic to be completed and vesting via Sablier
Main Components & Interactions to Illustrate
A. Client (Next.js App)
– Layers: React UI → Hooks/Services → Next.js API Routes → RPC Provider
– Providers: ThirdwebClientProvider, QueryClientProvider, ChainConnectProvider
B. API Layer (Serverless Functions)
– get-signed-presale-args: signs presale params for secure client purchase
– get-user: authenticates/returns user info (via JWT or session)
C. Blockchain Network
– RPC Endpoint (e.g., Infura/Alchemy/Sepolia node)
– Deployed Smart Contracts: OwnToken, Presale, Stake, VeOwn
D. Smart-Contract Project
– Hardhat scripts for deployment & verification
– Testing suite for each contract
E. External Services
– Wert: Fiat on-ramp integration
– Sablier: Vesting (future)
Architectural Patterns & Design Principles
• Separation of Concerns:
– UI vs. Data Fetch vs. API vs. Smart Contracts
• Provider Pattern (React Context)
• Hooks for business logic encapsulation
• Serverless functions as thin signing/auth layers
• EVM blockchain as stateful backend