Skip to content

DeInsure is a decentralized insurance protocol that replaces traditional insurance companies with smart contracts. Users can create insurance pools for specific risks (flight delays), buy coverage, and file claims - all automated via Chainlink oracles. The protocol features staking, governance, and instant payouts without human intervention.

Notifications You must be signed in to change notification settings

Turawa2/DeInsurance-contracts

Repository files navigation

DeInsure Smart Contracts

The smart contract implementation for DeInsure - a decentralized insurance protocol powered by Chainlink oracles.

Overview

DeInsure is a decentralized insurance protocol that replaces traditional insurance companies with smart contracts. Users can create insurance pools for specific risks (flight delays), buy coverage, and file claims - all automated via Chainlink oracles. The protocol features staking, governance, and instant payouts without human intervention.

Contracts

Core Contracts

  • DeInsureToken.sol: ERC20 governance token (DINS)

    • Total supply: 100M tokens
    • Used for staking, governance voting, and protocol incentives
  • PoolFactory.sol: Factory for creating insurance pools

    • Owner can create new pools for different risk types
    • Tracks all deployed pools
    • Manages pool lifecycle
  • InsurancePool.sol: Individual insurance pool contract

    • Users can deposit liquidity (premiums)
    • Buy coverage for specified amounts
    • File and process claims
    • Calculate premiums based on risk metrics
  • StakingPool.sol: Staking rewards contract

    • Users stake DINS tokens
    • Earn rewards based on protocol activity
    • Tracks accumulated rewards per share
  • RiskOracleManager.sol: Risk management and oracle integration

    • Integrates Chainlink oracles for price feeds
    • Manages risk metrics
    • Validates claim conditions

Quick Start

Prerequisites

  • Foundry (forge)
  • Node.js 16+

Installation

# Clone the repository
git clone https://github.com/Turawa2/deinsure-contracts.git
cd deinsure-contracts

# Install dependencies
forge install
npm install

Configuration

Create a .env file with your configuration:

# RPC URLs
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY

# Private key for deployment
PRIVATE_KEY=YOUR_PRIVATE_KEY

# Etherscan API key (optional, for verification)
ETHERSCAN_API_KEY=YOUR_ETHERSCAN_KEY

Compilation

forge build

Testing

forge test

Deployment

Deploy to Sepolia testnet:

forge script script/DeployOracle.s.sol --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY --broadcast

Contract Architecture

PoolFactory (Owner: 0x7ff90B8950B73b746C49F3b15dd036e6f15E9F51)
    ├── Creates InsurancePool instances
    └── Tracks deployed pools

InsurancePool (per risk type)
    ├── Manages pool liquidity
    ├── Processes coverage purchases
    ├── Handles claim submissions
    └── Calculates premiums

StakingPool
    ├── Accepts DINS token stakes
    ├── Distributes rewards
    └── Tracks user positions

DeInsureToken (DINS)
    ├── Governance token
    ├── 100M total supply
    └── Distributed to stakeholders

RiskOracleManager
    ├── Chainlink oracle integration
    ├── Risk metrics
    └── Claim validation

Key Functions

PoolFactory

// Create a new insurance pool
function createPool(
    string memory riskType,
    uint256 premiumRate,
    address oracle
) external onlyOwner returns (address poolAddress)

// Get all deployed pools
function getDeployedPools() external view returns (address[] memory)

InsurancePool

// Add liquidity to pool
function addLiquidity() external payable

// Purchase coverage
function purchasePolicy(uint256 coverageAmount) external payable

// File a claim
function fileClaim(uint256 policyId, uint256 claimAmount) external

// Get pool info
function getPoolInfo() external view returns (PoolInfo memory)

StakingPool

// Stake tokens
function stake(uint256 amount) external

// Withdraw stake
function withdraw(uint256 amount) external

// Get pending rewards
function getPendingRewards(address user) external view returns (uint256)

Deployed Addresses (Sepolia)

  • DeInsureToken: 0x41f285f95fB1EE50590eB6fe2aF3B1a717b2b1C4
  • PoolFactory: (see deployment logs)
  • StakingPool: 0xdA486fcd926919F26657e494F19a91aceD8D794b
  • RiskOracleManager: (see deployment logs)

Testing

Comprehensive test suites included:

  • test/InsurancePool.t.sol - Pool functionality tests
  • test/StakingPool.t.sol - Staking mechanism tests
  • test/OracleIntegration.t.sol - Oracle integration tests

Run all tests:

forge test -v

Security Considerations

  • ReentrancyGuard on all external calls
  • Owner-based access control
  • Oracle data validation
  • Claim amount limits
  • Premium rate bounds

Dependencies

  • OpenZeppelin Contracts (ERC20, Ownable, ReentrancyGuard)
  • Chainlink (AggregatorV3Interface, oracle price feeds)
  • Forge Standard Library

License

MIT

Support

For questions or issues, please open an issue on GitHub.

Development

See CONTRIBUTING.md for development guidelines.

About

DeInsure is a decentralized insurance protocol that replaces traditional insurance companies with smart contracts. Users can create insurance pools for specific risks (flight delays), buy coverage, and file claims - all automated via Chainlink oracles. The protocol features staking, governance, and instant payouts without human intervention.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published