A comprehensive Clarity smart contract for automated travel insurance on the Stacks blockchain, featuring policy management, automated claims processing, and oracle-based verification.
This smart contract provides a decentralized travel insurance platform where users can purchase policies, file claims, and receive automated payouts. The system uses an oracle mechanism for claim verification and maintains a premium pool for claim settlements.
- Purchase Insurance: Buy travel insurance with customizable coverage amounts
- Flexible Terms: Set start/end dates, destination, and flight information
- Premium Calculation: Automatic premium calculation at 5% of coverage amount
- Policy Cancellation: Cancel before start date with 80% refund
- Multiple Claim Types:
- Flight Delay (Type 1)
- Trip Cancellation (Type 2)
- Baggage Loss (Type 3)
- Medical Emergency (Type 4)
- Evidence-Based: Submit evidence hash with each claim
- Automated Validation: Claims validated against policy terms and dates
- Oracle Approval: Claims reviewed and approved by designated oracle
- Policy holder verification
- Date range validation
- Amount limits enforcement
- Duplicate claim prevention
- Balance checks before payouts
(purchase-policy coverage start-date end-date destination flight-number)Purchase a new travel insurance policy.
- Parameters:
coverage(uint): Maximum coverage amount in microSTXstart-date(uint): Policy start block heightend-date(uint): Policy end block heightdestination(string-ascii 50): Travel destinationflight-number(string-ascii 20): Flight number
- Premium: 5% of coverage amount (minimum 1 STX)
- Returns: Policy ID
(file-claim policy-id claim-type amount evidence-hash)File an insurance claim.
- Parameters:
policy-id(uint): Your policy IDclaim-type(uint): Type of claim (1-4)amount(uint): Claim amount in microSTXevidence-hash(string-ascii 64): Evidence document hash
- Returns: Claim ID
(cancel-policy policy-id)Cancel policy before start date (80% refund).
- Parameters:
policy-id(uint) - Returns: Refund amount
(approve-claim claim-id)Approve and process a claim (oracle only).
(deny-claim claim-id)Deny a claim (oracle only).
(get-policy policy-id)Retrieve policy details.
(get-claim claim-id)Retrieve claim details.
(get-user-policies user-principal)Get all policies for a user (returns list of policy IDs).
(get-policy-claims policy-id)Get all claims for a policy (returns list of claim IDs).
(is-policy-valid policy-id current-time)Check if policy is active and within valid dates.
(get-premium-pool)View total premium pool balance.
1- Active2- Expired3- Claimed4- Cancelled
0- Pending1- Approved2- Denied
| Code | Description |
|---|---|
| u100 | Owner only operation |
| u101 | Policy/claim not found |
| u102 | Unauthorized access |
| u103 | Invalid amount |
| u104 | Policy expired |
| u105 | Policy still active |
| u106 | Already claimed |
| u107 | Insufficient balance |
| u108 | Invalid dates |
| u109 | Claim denied |
(contract-call? .travel-insurance purchase-policy
u100000000 ;; 100 STX coverage
u1000 ;; Start at block 1000
u2000 ;; End at block 2000
"Paris" ;; Destination
"AA123" ;; Flight number
)
;; Premium: 5 STX (5% of 100 STX)
;; Returns: (ok u1)(contract-call? .travel-insurance file-claim
u1 ;; Policy ID
u1 ;; Flight delay claim
u50000000 ;; 50 STX claim amount
"abc123..." ;; Evidence hash
)
;; Returns: (ok u1)(contract-call? .travel-insurance approve-claim u1)
;; 50 STX transferred to policy holder
;; Returns: (ok true)- Contract Owner: The deployer becomes the contract owner and initial oracle
- Minimum Premium: 1 STX (1,000,000 microSTX)
- Oracle Setup: Use
set-oracleto designate claim approver - Time Units: All dates use block height
- Only policy holders can file claims on their policies
- Only the designated oracle can approve/deny claims
- Policies must be active and within date range for claims
- Claims cannot exceed policy coverage amount
- Premium pool must have sufficient balance for payouts
- Emergency withdrawal restricted to contract owner
- Multi-oracle consensus mechanism
- Automated claim approval based on external data feeds
- Dynamic premium calculation based on risk factors
- Partial claims support
- Policy extensions and upgrades
- Staking mechanism for oracle participation