Skip to content

Latest commit

Β 

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

WeInsure - Parametric Insurance Platform

A blockchain-based parametric insurance platform for event cancellations using weather data oracles and smart contracts.

🎯 Overview

WeInsure provides automated insurance coverage for events based on weather conditions. The platform uses Chainlink oracles to fetch real-time weather data and automatically triggers payouts when predefined weather thresholds are met.

Key Features

  • Parametric Insurance: Automated payouts based on objective weather data
  • Blockchain-Based: Transparent, immutable smart contracts on Ethereum
  • Oracle Integration: Real-time weather data from multiple sources
  • NFT Policies: Each policy is represented as an NFT for easy ownership tracking
  • Award-Winning UI/UX: Professional, accessible design with 3-color palette
  • Wallet Isolation: Each wallet gets its own separate policy dashboard
  • Modern Frontend: Clean Next.js application with seamless Web3 integration
  • Automated Triggers: No claims process - payouts are automatic when conditions are met
  • Real-time Notifications: Professional notification system with visual indicators
  • Mobile Optimized: Responsive design that works perfectly on all devices

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      β”‚    β”‚   Backend       β”‚    β”‚   Blockchain    β”‚
β”‚   (Next.js)     │◄──►│   (Node.js)     │◄──►│   (Sepolia)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β”‚                       β”‚                       β”‚
         β–Ό                       β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Web3 Wallet   β”‚    β”‚   MongoDB       β”‚    β”‚   Smart         β”‚
β”‚   (MetaMask)    β”‚    β”‚   Weather APIs  β”‚    β”‚   Contracts     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Smart Contracts

  • PolicyFactory: Creates and manages insurance policies
  • PolicyNFT: ERC721 tokens representing insurance policies
  • Escrow: Manages premium payments and payouts
  • TriggerContract: Handles weather data and trigger logic

Frontend (Next.js)

  • Award-Winning UI/UX: Professional 3-color design system with optimal accessibility
  • Clean Architecture: Component-based design with consistent styling
  • Web3 Integration: Seamless wallet connection with RainbowKit
  • Wallet-Specific Data: Isolated policy data for each connected wallet
  • Real-time Monitoring: Live weather data and risk visualization
  • Responsive Design: Mobile-first approach with smooth animations
  • Professional Components: Clean cards, tables, forms, and navigation

Backend Services

  • Premium Calculator: Actuarial calculations based on historical weather data
  • Weather API Integration: Fetches data from multiple weather services
  • MongoDB Database: Stores policy metadata and weather history

Oracle Adapter

  • Multi-Source Weather Data: OpenWeatherMap, NOAA, backup APIs
  • Consensus Mechanism: Validates data across multiple sources
  • Chainlink Integration: Submits verified data to blockchain

πŸš€ Quick Start

Prerequisites

  • Node.js >= 18.0.0
  • MongoDB
  • Ethereum wallet with Sepolia testnet ETH
  • API keys for weather services (optional for testing)

Installation

  1. Clone the repository
git clone https://github.com/YOUR_USERNAME/WeInsure.git
cd WeInsure
  1. Install all dependencies
npm run install:all
  1. Configure environment variables
# Copy example files and configure with your API keys
cp .env.example .env
cp backend/.env.example backend/.env
cp oracle-adapter/.env.example oracle-adapter/.env
cp frontend/.env.example frontend/.env.local

# Edit each .env file with your actual API keys and configuration
# See the .env.example files for detailed comments on each variable

Deployment & Setup

  1. Compile and deploy smart contracts
npm run compile
npm run deploy:sepolia
  1. Setup frontend with contract addresses
npm run setup:frontend
  1. Start all services
npm run dev

This will start:

🎨 Frontend Features

✨ Award-Winning UI/UX Design

WeInsure features a professional, clean design system built with modern web standards:

🎯 Design System

  • Professional 3-Color Palette:
    • Primary Blue (#2563eb) - Trust and reliability
    • Neutral Gray (#64748b) - Clean readability
    • Success Green (#10b981) - Positive actions
  • Typography: Inter font family for optimal readability
  • Accessibility: WCAG compliant color contrasts and interactions
  • Responsive: Mobile-first design approach

🏠 Landing & Navigation

  • Clean Navbar: Professional navigation with wallet integration
  • USDC Balance Display: Real-time balance tracking with visual indicators
  • Responsive Menu: Smooth mobile navigation experience
  • Active States: Clear indication of current page location

πŸ“ Create Policy Page

  • Multi-Step Form: Intuitive policy creation workflow
  • Real-time Validation: Instant feedback on form inputs
  • Premium Calculator: Live premium calculation with breakdown
  • Weather Threshold Setup: Visual threshold configuration
  • Smart Contract Integration: Seamless blockchain interactions

πŸ“Š Dashboard

  • Wallet-Specific Data: Each wallet has isolated policy data
  • Summary Cards: Clean metric displays with hover animations
  • Active Policy Monitor: Real-time weather risk visualization
  • Policy History Table: Professional table design with status badges
  • Live Risk Monitor: Progress bars showing current vs trigger thresholds
  • Notification System: Clean notification cards with read/unread states

πŸ”” Notification Features

  • Real-time Updates: Instant notifications for policy events
  • Visual Indicators: Unread badges and status indicators
  • Persistent Storage: Notifications persist across sessions
  • Clean UI: Professional notification cards with proper hierarchy

πŸ“± Mobile Experience

  • Responsive Design: Optimized for all screen sizes
  • Touch-Friendly: Proper touch targets and interactions
  • Performance: Smooth animations and transitions
  • Accessibility: Screen reader compatible and keyboard navigable

🏠 Home Page

  • Hero section with clear value proposition
  • Feature highlights and platform statistics
  • How it works explanation
  • Call-to-action sections

πŸ“ Create Policy

  • Step 1: Event details and location
  • Step 2: Weather thresholds configuration
  • Step 3: Review and payment
  • Real-time premium calculation
  • Smart contract integration

πŸ“Š Dashboard

  • Policy overview and statistics
  • Real-time weather monitoring
  • Policy status tracking
  • Quick actions and navigation

πŸ“ˆ Monitor

  • Live weather charts (24h history)
  • Policy risk assessment
  • Alert system for critical conditions
  • Multi-policy monitoring

πŸ“‹ Available Scripts

Main Commands

npm run install:all      # Install all dependencies
npm run dev             # Start all services (frontend, backend, oracle)
npm run compile         # Compile smart contracts
npm test               # Run contract tests
npm run deploy:sepolia  # Deploy to Sepolia testnet
npm run verify:sepolia  # Verify contracts on Etherscan

Individual Services

# Frontend
npm run frontend:dev    # Start frontend development server
npm run frontend:build  # Build frontend for production

# Backend
npm run backend:dev     # Start backend development server
npm run backend:start   # Start backend production server

# Oracle Adapter
npm run oracle:dev      # Start oracle with auto-restart
npm run oracle:start    # Start oracle production mode

Utilities

npm run setup:frontend  # Setup frontend with contract addresses
npm run setup:testnet   # Setup testnet environment
npm run interact        # Test contract interactions
npm run monitor         # Monitor policies and weather

πŸ§ͺ Testing

Smart Contract Tests

npm test                # Run all tests
npm run test:coverage   # Run with coverage report
npm run test:gas        # Analyze gas usage

Test Results

WeInsure Integration Tests
  βœ… Should complete full policy lifecycle - normal weather
  βœ… Should complete full policy lifecycle - cancellation trigger

PolicyFactory
  βœ… Should create a policy successfully

TriggerContract
  βœ… Should register trigger conditions
  βœ… Should process weather data and trigger cancellation
  βœ… Should calculate 24-hour rainfall correctly

6 passing (2s)

πŸ“Š Policy Workflow

1. Policy Creation

  1. Connect Web3 wallet to frontend
  2. Fill out event details and location
  3. Set weather thresholds for triggers
  4. System calculates premium using actuarial models
  5. Pay premium in USDC and receive Policy NFT

2. Weather Monitoring

  1. Oracle adapter polls weather APIs hourly
  2. Data validated using consensus mechanism
  3. Frontend displays real-time weather charts
  4. Risk levels calculated and displayed

3. Trigger Evaluation

  1. Postponement: Wind β‰₯ threshold for consecutive hours β†’ 50% payout
  2. Cancellation: Rain β‰₯ threshold in 24h OR wind β‰₯ threshold β†’ 100% payout
  3. Payouts are automatic and instant
  4. Policy NFT status updated

πŸ”§ Configuration

Weather Thresholds

  • Postponement Rainfall: Typically 10-15mm in 1 hour
  • Postponement Wind: Typically 50-60 km/h sustained
  • Cancellation Rainfall: Typically 20-25mm in 24 hours
  • Cancellation Wind: Typically 80-100 km/h

Premium Calculation

ExpectedLoss = (Postponement% Γ— Coverage Γ— Prob_p) + (100% Γ— Coverage Γ— Prob_c)
PurePremium = ExpectedLoss
LoadedPremium = PurePremium / (1 - TargetLossRatio)

πŸ›‘οΈ Security Features

  • Multi-source Oracle Consensus: Prevents single point of failure
  • OpenZeppelin Standards: Battle-tested smart contract implementations
  • Access Control: Role-based permissions throughout
  • Reentrancy Protection: All external calls are protected
  • Input Validation: Comprehensive parameter validation

🌐 Network Support

  • Sepolia Testnet βœ… (Primary development network)
  • Ethereum Mainnet (Production ready)
  • Polygon (Future deployment)
  • Arbitrum (Future deployment)

πŸ“ Project Structure

WeInsure/
β”œβ”€β”€ contracts/              # Smart contracts
β”‚   β”œβ”€β”€ PolicyFactory.sol
β”‚   β”œβ”€β”€ PolicyNFT.sol
β”‚   β”œβ”€β”€ Escrow.sol
β”‚   β”œβ”€β”€ TriggerContract.sol
β”‚   └── mockERC20.sol
β”œβ”€β”€ frontend/               # Next.js frontend with award-winning UI/UX
β”‚   β”œβ”€β”€ app/               # App router pages with clean layouts
β”‚   β”‚   β”œβ”€β”€ components/    # Professional reusable components
β”‚   β”‚   β”œβ”€β”€ dashboard/     # Wallet-specific dashboard
β”‚   β”‚   β”œβ”€β”€ create-policy/ # Multi-step policy creation
β”‚   β”‚   └── globals.css    # Professional 3-color design system
β”‚   └── lib/              # Utilities and API client
β”œβ”€β”€ backend/               # Node.js backend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ controllers/   # API controllers
β”‚   β”‚   β”œβ”€β”€ models/        # Database models
β”‚   β”‚   β”œβ”€β”€ routes/        # API routes
β”‚   β”‚   └── services/      # Business logic
β”‚   └── server.js
β”œβ”€β”€ oracle-adapter/        # Weather oracle service
β”‚   β”œβ”€β”€ index.js          # Main oracle service
β”‚   β”œβ”€β”€ weather-fetcher.js # Weather API integration
β”‚   β”œβ”€β”€ consensus.js      # Data validation
β”‚   └── chainlink-integration.js
β”œβ”€β”€ scripts/              # Deployment and utility scripts
β”œβ”€β”€ test/                # Smart contract tests
└── package.json         # Main project configuration

🎯 User Journey

Seamless User Experience

  1. Connect Wallet β†’ Clean wallet connection interface with professional styling
  2. Wallet Isolation β†’ Each wallet gets its own isolated policy dashboard
  3. Create Policy β†’ Intuitive multi-step form with real-time validation
  4. Visual Feedback β†’ Professional notifications and status updates
  5. Monitor Weather β†’ Clean dashboard with live risk visualization
  6. Automatic Payouts β†’ Instant notifications when payouts are triggered
  7. Policy Management β†’ Professional table interface for policy history

Design Highlights

  • Professional Aesthetics: Clean, modern design suitable for financial applications
  • Optimal Readability: High contrast colors and proper typography
  • Smooth Interactions: Subtle animations and hover effects
  • Mobile Optimized: Responsive design that works on all devices
  • Accessibility First: WCAG compliant design for all users

πŸš€ Deployment

Local Development

npm run dev  # Starts all services locally

Production Deployment

  1. Smart Contracts: Deploy to mainnet using deployment scripts
  2. Backend: Deploy to cloud service (AWS, GCP, etc.)
  3. Frontend: Deploy to Vercel or similar platform
  4. Oracle: Run as a service with proper monitoring

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support


WeInsure - Protecting events with blockchain-powered parametric insurance πŸ›‘οΈβ›ˆοΈ

About

Parametric Insurance for Event Cancellations - Create smart contracts that automatically trigger payouts for event cancellations based on trusted weather or external oracle data, reducing delays in insurance claims.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages