Skip to content

A decentralized platform built on the Stacks blockchain using Clarity smart contracts. This autonomous system eliminates traditional insurance intermediaries by automating the entire insurance lifecycle—from policy creation and premium collection to claims processing and payouts—all executed through transparent, immutable smart contract logic.

Notifications You must be signed in to change notification settings

d-olayanju/Vehicle-Insurance-Automation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Vehicle Insurance Automation Smart Contract

A comprehensive Clarity smart contract for automated vehicle insurance management on the Stacks blockchain. This contract handles policy lifecycle management, premium payments, claims processing, and automated settlements without intermediaries.


Features

🚗 Policy Management

  • Create new insurance policies with customizable coverage and duration
  • Automatic premium collection and reserve pool management
  • Policy renewal with extended coverage periods
  • Policy cancellation with 50% refund mechanism
  • Real-time policy status tracking (active, expired, cancelled)

📋 Claims Processing

  • File insurance claims against active policies
  • Owner-controlled claim approval/rejection workflow
  • Automated payout processing from reserve pool
  • Complete claim history tracking per policy
  • Status tracking: pending, approved, rejected, paid

💰 Financial Management

  • Centralized reserve pool for all premiums
  • Automated fund validation before payouts
  • Owner-controlled reserve withdrawals
  • Deposit functionality for reserve replenishment
  • Transparent fund tracking

🔒 Security Features

  • Authorization checks for all sensitive operations
  • Input validation for all user-provided data
  • Owner-only administrative controls
  • Active policy validation before claims
  • Comprehensive error handling with 11 error codes

Smart Contract Architecture

Data Structures

Policies Map

{
    owner: principal,
    vehicle-id: string-ascii 50,
    premium: uint,
    coverage: uint,
    start-block: uint,
    end-block: uint,
    status: uint  // 0=inactive, 1=active, 2=expired, 3=cancelled
}

Claims Map

{
    policy-id: uint,
    claimant: principal,
    amount: uint,
    description: string-ascii 256,
    filed-block: uint,
    status: uint,  // 0=pending, 1=approved, 2=rejected, 3=paid
    approved-amount: uint
}

Usage Guide

For Policyholders

1. Create a Policy

(contract-call? .vehicle-insurance create-policy 
    "ABC-1234-XYZ"  ;; vehicle-id
    u1000000        ;; premium (1 STX in microSTX)
    u50000000       ;; coverage (50 STX)
    u52560          ;; duration (~1 year in blocks)
)

2. Renew Policy

(contract-call? .vehicle-insurance renew-policy 
    u1              ;; policy-id
    u52560          ;; additional duration
)

3. File a Claim

(contract-call? .vehicle-insurance file-claim 
    u1              ;; policy-id
    u10000000       ;; claim amount (10 STX)
    "Vehicle accident on Highway 101, front bumper damage"
)

4. Cancel Policy

(contract-call? .vehicle-insurance cancel-policy u1)

For Contract Owner

1. Approve Claim

(contract-call? .vehicle-insurance approve-claim 
    u1              ;; claim-id
    u8000000        ;; approved amount (8 STX)
)

2. Reject Claim

(contract-call? .vehicle-insurance reject-claim u1)

3. Process Payout

(contract-call? .vehicle-insurance process-payout u1)

4. Update Policy Status

(contract-call? .vehicle-insurance update-policy-status 
    u1              ;; policy-id
    u2              ;; new status (2=expired)
)

5. Withdraw Reserves

(contract-call? .vehicle-insurance withdraw-reserve 
    u5000000        ;; amount
    'SP123...       ;; recipient principal
)

Read-Only Functions

Check Policy Details

(contract-call? .vehicle-insurance get-policy u1)

Check Claim Status

(contract-call? .vehicle-insurance get-claim u1)

Get User's Policies

(contract-call? .vehicle-insurance get-user-policies 'SP123...)

Check Reserve Pool

(contract-call? .vehicle-insurance get-reserve-pool)

Verify Policy Active Status

(contract-call? .vehicle-insurance is-policy-active u1)

Error Codes

Code Constant Description
u100 err-owner-only Operation requires contract owner
u101 err-not-found Policy or claim not found
u102 err-unauthorized User not authorized for this action
u103 err-invalid-amount Invalid monetary amount
u104 err-policy-expired Policy is expired or inactive
u105 err-policy-active Policy must be inactive
u106 err-insufficient-funds Insufficient funds in reserve pool
u107 err-claim-exists Claim already exists
u108 err-invalid-status Invalid status value
u109 err-payment-failed Payment transaction failed
u110 err-invalid-input Invalid input data

Status Codes

Policy Status

  • 0: Inactive
  • 1: Active
  • 2: Expired
  • 3: Cancelled

Claim Status

  • 0: Pending review
  • 1: Approved (awaiting payout)
  • 2: Rejected
  • 3: Paid

Security Considerations

Implemented Safeguards

  • All user inputs are validated before processing
  • Authorization checks on all state-changing operations
  • Amount bounds checking to prevent overflow
  • Reserve pool validation before payouts
  • Active policy verification for claims
  • Status transition controls

⚠️ Important Notes

  • Only the contract owner can approve/reject claims and process payouts
  • Policies must be active for claims to be filed
  • Claims cannot exceed policy coverage limits
  • Policy cancellation provides 50% refund only
  • Reserve pool must have sufficient funds for payouts

Deployment Instructions

  1. Deploy Contract

    clarinet contract deploy vehicle-insurance
  2. Verify Deployment

    clarinet console
  3. Test Functions

    clarinet test

Example Workflow

Complete Insurance Lifecycle

  1. User purchases policy → Premium goes to reserve pool
  2. Policy becomes active → Coverage starts immediately
  3. User experiences accident → Files claim with description
  4. Owner reviews claim → Approves with assessment amount
  5. Owner processes payout → Funds transferred to claimant
  6. Claim marked as paid → Reserve pool updated

Testing

Unit Tests Coverage

  • Policy creation and validation
  • Premium payment processing
  • Policy renewal and cancellation
  • Claim filing and validation
  • Claim approval/rejection workflow
  • Payout processing
  • Authorization checks
  • Input validation
  • Reserve pool management

About

A decentralized platform built on the Stacks blockchain using Clarity smart contracts. This autonomous system eliminates traditional insurance intermediaries by automating the entire insurance lifecycle—from policy creation and premium collection to claims processing and payouts—all executed through transparent, immutable smart contract logic.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published