Skip to content

This contract enables users to purchase insurance coverage by paying premiums in STX tokens and subsequently file claims against their purchased policies. The contract operates autonomously, managing a reserve fund from collected premiums and processing claims based on predefined coverage limits.

Notifications You must be signed in to change notification settings

ope-olawale/Insurance-Coverage-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Insurance Coverage System

A Clarity smart contract that implements a decentralized insurance system on the Stacks blockchain, allowing users to purchase coverage policies and file claims against their purchased coverage.

Overview

This smart contract enables users to purchase insurance coverage by paying premiums in STX tokens. The contract maintains a reserve fund from collected premiums and allows policyholders to file claims up to their coverage limit. The contract owner can also create policies with custom parameters.

Key Features

  • Policy Purchase: Users can buy insurance coverage for a specified amount and duration
  • Premium Calculation: Premiums are automatically calculated based on coverage amount and duration
  • Claim Filing: Policyholders can submit claims up to their coverage limit
  • Reserve Fund Management: All premiums are collected into a secure reserve fund
  • Owner Administration: Contract owner can create custom policies

Constants

Constant Value Description
max-coverage-limit 1,000,000,000 Maximum coverage amount allowed
max-policy-duration 52,560 blocks Maximum policy duration (~1 year)
min-premium 1,000 Minimum premium amount required

Functions

Public Functions

purchase-coverage

(purchase-coverage (coverage-limit uint) (duration uint))

Allows users to purchase insurance coverage.

  • Parameters:
    • coverage-limit: Amount of coverage desired (in micro-STX)
    • duration: Policy duration in blocks
  • Premium Formula: coverage-limit × (1/100) × duration
  • Returns: (ok true) on success
  • Errors:
    • err-invalid-params: Invalid coverage amount, duration, or calculated premium
    • Transfer errors if insufficient STX balance

file-claim

(file-claim (claim-amount uint))

Allows policyholders to submit a claim against their coverage.

  • Parameters:
    • claim-amount: Amount being claimed (in micro-STX)
  • Requirements: User must have an active policy with sufficient coverage
  • Returns: (ok true) on success
  • Errors:
    • err-not-insured: User has no active policy
    • err-invalid-claim: Claim amount exceeds coverage limit
    • err-insufficient-balance: Reserve fund cannot cover the claim

create-policy (Owner Only)

(create-policy (coverage-limit uint) (premium uint) (duration uint))

Allows the contract owner to create a custom policy.

  • Parameters:
    • coverage-limit: Coverage amount
    • premium: Premium amount
    • duration: Policy duration in blocks
  • Returns: (ok true) on success
  • Errors:
    • err-owner-only: Caller is not the contract owner
    • err-invalid-params: Invalid parameters

Read-Only Functions

get-policy-details

(get-policy-details (policyholder principal))

Returns policy information for a given principal.

  • Returns: Policy data or none if no policy exists
    • coverage-limit: Maximum claimable amount
    • premium: Premium paid
    • expiry: Block height when policy expires

get-claim-details

(get-claim-details (claimant principal))

Returns claim information for a given principal.

  • Returns: Claim data or none if no claim exists
    • claim-amount: Amount claimed
    • approved: Approval status (always true for processed claims)

get-fund-balance

(get-fund-balance)

Returns the current balance of the reserve fund.

Data Structures

Insurance Policies Map

Stores active policies for each policyholder:

{
    coverage-limit: uint,
    premium: uint,
    expiry: uint
}

Claim Submissions Map

Stores processed claims:

{
    claim-amount: uint,
    approved: bool
}

Error Codes

Code Constant Description
u100 err-owner-only Action restricted to contract owner
u101 err-invalid-claim Claim amount exceeds coverage or invalid
u102 err-insufficient-balance Reserve fund cannot cover the claim
u103 err-not-insured User has no active policy
u104 err-invalid-params Invalid input parameters

Usage Example

Purchasing Coverage

;; Purchase 10,000 STX coverage for 5,000 blocks
(contract-call? .insurance-coverage-system purchase-coverage u10000000000 u5000)
;; Premium will be calculated as: 10,000 × (1/100) × 5,000 = 500,000 micro-STX

Filing a Claim

;; File a claim for 5,000 STX
(contract-call? .insurance-coverage-system file-claim u5000000000)

Checking Policy Status

;; Check your policy details
(contract-call? .insurance-coverage-system get-policy-details tx-sender)

Security Considerations

  • Overflow Protection: Includes checks to prevent arithmetic overflow
  • Owner Privileges: Only the contract owner can create custom policies
  • Coverage Limits: Enforces maximum coverage and duration limits
  • Minimum Premiums: Ensures economic viability with minimum premium requirements
  • Fund Validation: Verifies reserve fund sufficiency before processing claims

Deployment

The contract owner is automatically set to tx-sender at deployment time. Ensure you deploy from the intended owner address.

About

This contract enables users to purchase insurance coverage by paying premiums in STX tokens and subsequently file claims against their purchased policies. The contract operates autonomously, managing a reserve fund from collected premiums and processing claims based on predefined coverage limits.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published