The smart contract implementation for DeInsure - a decentralized insurance protocol powered by Chainlink oracles.
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.
-
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
- Foundry (forge)
- Node.js 16+
# Clone the repository
git clone https://github.com/Turawa2/deinsure-contracts.git
cd deinsure-contracts
# Install dependencies
forge install
npm installCreate 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_KEYforge buildforge testDeploy to Sepolia testnet:
forge script script/DeployOracle.s.sol --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY --broadcastPoolFactory (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
// 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)// 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)// 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)- DeInsureToken:
0x41f285f95fB1EE50590eB6fe2aF3B1a717b2b1C4 - PoolFactory: (see deployment logs)
- StakingPool:
0xdA486fcd926919F26657e494F19a91aceD8D794b - RiskOracleManager: (see deployment logs)
Comprehensive test suites included:
test/InsurancePool.t.sol- Pool functionality teststest/StakingPool.t.sol- Staking mechanism teststest/OracleIntegration.t.sol- Oracle integration tests
Run all tests:
forge test -v- ReentrancyGuard on all external calls
- Owner-based access control
- Oracle data validation
- Claim amount limits
- Premium rate bounds
- OpenZeppelin Contracts (ERC20, Ownable, ReentrancyGuard)
- Chainlink (AggregatorV3Interface, oracle price feeds)
- Forge Standard Library
MIT
For questions or issues, please open an issue on GitHub.
See CONTRIBUTING.md for development guidelines.