Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Insurance Coverage System - Smart Contract Description
Summary
The Insurance Coverage System is a decentralized insurance protocol built on the Stacks blockchain using Clarity smart contract language. It 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.
Core Functionality
Policy Purchase Mechanism
Users can acquire insurance coverage by calling the
purchase-coveragefunction with two parameters: the desired coverage amount and policy duration. The contract automatically calculates the required premium using the formula: Premium = Coverage Limit × (1/100) × Duration. Upon payment, the premium is transferred to the contract's reserve fund, and a policy record is created containing the coverage limit, premium paid, and expiry block height.Claim Processing
Policyholders can file claims through the
file-claimfunction by specifying the claim amount. The contract validates that:Upon successful validation, the claim amount is transferred from the reserve fund to the claimant, and a claim record is created with approval status.
Administrative Controls
The contract owner (set at deployment) has elevated privileges to create custom policies via the
create-policyfunction, allowing manual specification of coverage limits, premiums, and durations. This enables flexible policy configuration beyond the standard automated premium calculation.Technical Architecture
Data Storage
The contract utilizes two primary data maps:
A single data variable
reserve-fundmaintains the aggregate balance of all collected premiums and available funds for claim payouts.Safety Constraints
The contract enforces several safety parameters:
Error Handling
The contract implements comprehensive error handling with five distinct error codes covering authorization failures, invalid parameters, insufficient funds, missing policies, and invalid claims. All state-changing operations validate inputs and fund availability before execution.
Use Cases
This smart contract is suitable for:
Key Advantages
Limitations & Considerations
Integration Points
External systems can integrate with this contract by:
get-policy-detailsfor coverage verificationget-fund-balancefor solvency assessmentget-claim-detailsfor audit purposespurchase-coverageandfile-claimfunctionsSecurity Model
The contract employs a trust-minimized security model where:
stx-transfer?function with error propagationas-contractcontext to transfer from the contract's balance