Skip to content

[Contract] Build Insurance Policy Lifecycle#494

Merged
truthixify merged 2 commits intoDistinctCodes:mainfrom
Josue19-08:feat/insurance-policy-lifecycle
Feb 22, 2026
Merged

[Contract] Build Insurance Policy Lifecycle#494
truthixify merged 2 commits intoDistinctCodes:mainfrom
Josue19-08:feat/insurance-policy-lifecycle

Conversation

@Josue19-08
Copy link
Copy Markdown
Contributor

Summary

This PR implements a complete on-chain insurance policy management system for tokenized assets as specified in #474.

Changes

Data Structure

  • InsurancePolicy struct with all required fields:
    • Policy identifier, holder and insurer addresses
    • Asset reference
    • Policy classification: Liability, Property, Comprehensive, Custom
    • Coverage and deductible amounts
    • Premium value
    • Start/end timestamps
    • Status: Active, Suspended, Expired, Cancelled
    • Auto-renewal flag
    • Last payment timestamp

Core Functions

  • create_policy() - Creates policies with comprehensive validation:
    • Date validation (start < end, not in past)
    • Coverage/deductible validation
    • Asset indexing
    • Returns policy ID
  • cancel_policy() - Holder or insurer authorized
  • suspend_policy() - Insurer only
  • expire_policy() - Permissionless, requires end_date < current timestamp
  • renew_policy() - Insurer only
  • get_policy() - Retrieves individual policy details
  • get_asset_policies() - Gets all policies for an asset

Features

  • Date Validation: Ensures start_date < end_date and start_date not in past
  • Status Transitions: Validates state transitions (e.g., Active → Cancelled/Suspended)
  • Asset Index: Maintains all policy IDs per asset
  • Authorization: Proper auth checks for all operations
  • Permissionless Expiration: Anyone can expire a policy after end_date

Acceptance Criteria Met

  • ✅ Status transitions follow valid patterns
  • ✅ Expiration fails if end date hasn't arrived
  • ✅ Asset index correctly maintains all policy identifiers

Tests Added (14 new tests)

  • test_create_policy_success - Valid policy creation
  • test_create_policy_invalid_dates - Date validation
  • test_create_policy_invalid_coverage - Coverage validation
  • test_cancel_policy_by_holder - Holder can cancel
  • test_cancel_policy_by_insurer - Insurer can cancel
  • test_cancel_policy_unauthorized - Unauthorized cannot cancel
  • test_suspend_policy - Insurer can suspend
  • test_suspend_policy_unauthorized - Only insurer can suspend
  • test_expire_policy_before_end_date - Cannot expire early
  • test_expire_policy_after_end_date - Can expire after end_date
  • test_renew_policy - Renew active policy
  • test_renew_expired_policy - Renew expired policy
  • test_get_asset_policies - Asset index works
  • test_status_transition_validation - Valid state transitions

All 55 contract tests passing (41 existing + 14 new)

Related Issue

Closes #474

🤖 Generated with Claude Code

Josue19-08 and others added 2 commits February 21, 2026 21:29
Enhance execute_detokenization() to fully eliminate tokens from circulation and clear all tokenization records:
- Remove all token holder balances
- Clear token locks for all holders
- Remove unclaimed dividends
- Delete token holders list
- Remove transfer restrictions and whitelist
- Clear token metadata
- Remove TokenizedAsset record (eliminates all tokens)
- Clear voting records before removal

Add comprehensive tests:
- test_token_elimination_on_execution: Verifies complete token removal
- test_cannot_propose_after_execution: Ensures no re-proposals after execution

Fixes DistinctCodes#473

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Complete implementation of on-chain insurance policy management for tokenized assets:

Policy Management Functions:
- create_policy(): Create policies with date validation and asset indexing
- cancel_policy(): Cancel policy (holder or insurer authorized)
- suspend_policy(): Suspend policy (insurer only)
- expire_policy(): Expire policy (permissionless, requires end_date passed)
- renew_policy(): Renew policy (insurer only)
- get_policy(): Retrieve individual policy details
- get_asset_policies(): Get all policies for an asset

Data Structure:
- InsurancePolicy with policy_type (Liability, Property, Comprehensive, Custom)
- PolicyStatus: Active, Suspended, Expired, Cancelled
- Coverage amount, deductible, premium tracking
- Start/end timestamps with validation
- Auto-renewal flag and last payment tracking

Features:
- Date validation (start_date < end_date, not in past)
- Status transition validation (valid state transitions only)
- Asset index maintains all policy IDs per asset
- Authorization checks (holder/insurer for cancel, insurer for suspend/renew)
- Permissionless expiration when end_date passes

Comprehensive test suite (14 tests):
- Policy creation with validation
- Cancellation by holder and insurer
- Suspension (authorized and unauthorized)
- Expiration (before and after end_date)
- Renewal of active and expired policies
- Asset policy index
- Status transition validation

All 55 contract tests passing.

Fixes DistinctCodes#474

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Feb 22, 2026

@Josue19-08 is attempting to deploy a commit to the naijabuz's projects Team on Vercel.

A member of the Team first needs to authorize it.

@truthixify truthixify merged commit dcc0ef0 into DistinctCodes:main Feb 22, 2026
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Contract] Build Insurance Policy Lifecycle

2 participants