Travel Insurance Automation

What it does:
Automates travel insurance issuance, monitoring, and claim payouts using smart contracts and oracles for flight delays, cancellations, or other predefined events.

Why it matters:
Eliminates manual claim processing, ensures instant and transparent payouts, reduces fraud, and improves traveler experience with verifiable, automated insurance handling.

How it works:

  • Travelers purchase travel insurance policies on-chain with predefined coverage and conditions

  • Smart contracts integrate with oracles to monitor flights, weather, or travel disruptions

  • Claims are automatically triggered when conditions are met (e.g., delayed flight, canceled trip)

  • Payouts are released instantly to travelers in stablecoins or crypto

  • Policies, claims, and payouts are immutable and auditable

  • Integrates with Tokenized Wallets, Decentralized Identity Verification, or Personal Goal Accountability

  • Dashboards provide policy status, claim history, and pending event monitoring

      // SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/access/Ownable.sol";

/**
 * @title TravelInsuranceAutomation
 * @author Nam
 * @notice Automates travel insurance purchase, monitoring, and claim payouts on-chain
 */
contract TravelInsuranceAutomation is Ownable {

    struct Policy {
        address payable traveler;
        uint256 premium; // in wei or stablecoin
        uint256 coverageAmount;
        uint256 startTime;
        uint256 endTime;
        bool active;
        bool claimed;
    }

    mapping(uint256 => Policy) public policies;
    uint256 public policyCount;

    mapping(address => bool) public authorizedOracles;

    // -------------------- EVENTS --------------------

    event OracleApproved(address oracle);
    event OracleRevoked(address oracle);
    event PolicyPurchased(uint256 indexed policyId, address traveler, uint256 premium, uint256 coverageAmount);
    event ClaimPaid(uint256 indexed policyId, address traveler, uint256 payout);

    // -------------------- ORACLE MANAGEMENT --------------------

    function approveOracle(address _oracle) external onlyOwner {
        authorizedOracles[_oracle] = true;
        emit OracleApproved(_oracle);
    }

    function revokeOracle(address _oracle) external onlyOwner {
        authorizedOracles[_oracle] = false;
        emit OracleRevoked(_oracle);
    }

    modifier onlyOracle() {
        require(authorizedOracles[msg.sender], "Not authorized oracle");
        _;
    }

    // -------------------- POLICY MANAGEMENT --------------------

    function purchasePolicy(uint256 _coverageAmount, uint256 _duration) external payable {
        require(msg.value > 0, "Premium required");
        require(_coverageAmount > 0, "Coverage must be >0");
        require(_duration > 0, "Duration must be >0");

        policyCount += 1;
        policies[policyCount] = Policy({
            traveler: payable(msg.sender),
            premium: msg.value,
            coverageAmount: _coverageAmount,
            startTime: block.timestamp,
            endTime: block.timestamp + _duration,
            active: true,
            claimed: false
        });

        emit PolicyPurchased(policyCount, msg.sender, msg.value, _coverageAmount);
    }

    // -------------------- CLAIM MANAGEMENT --------------------

    function triggerClaim(uint256 _policyId) external onlyOracle {
        Policy storage p = policies[_policyId];
        require(p.active, "Policy inactive");
        require(!p.claimed, "Already claimed");
        require(block.timestamp <= p.endTime, "Policy expired");

        p.claimed = true;
        p.active = false;
        p.traveler.transfer(p.coverageAmount);

        emit ClaimPaid(_policyId, p.traveler, p.coverageAmount);
    }

    // -------------------- VIEW FUNCTIONS --------------------

    function isPolicyActive(uint256 _policyId) external view returns (bool) {
        return policies[_policyId].active;
    }

    function hasClaimed(uint256 _policyId) external view returns (bool) {
        return policies[_policyId].claimed;
    }

    // -------------------- FUNDING --------------------

    receive() external payable {}
}