Skip to content

feat(insurance): integrate external insurance providers (#250)#412

Merged
LaGodxy merged 2 commits intoMettaChain:mainfrom
Nuel-ship-it:feature/250-external-insurance-providers
Apr 29, 2026
Merged

feat(insurance): integrate external insurance providers (#250)#412
LaGodxy merged 2 commits intoMettaChain:mainfrom
Nuel-ship-it:feature/250-external-insurance-providers

Conversation

@Nuel-ship-it
Copy link
Copy Markdown
Contributor

Summary

Implements an on-chain registry and hybrid coverage request flow that connects PropChain policies to traditional (off-chain) insurance companies.

Design

Because smart contracts cannot make outbound HTTP calls, the integration uses a relayer pattern:

  1. The policyholder submits a coverage request on-chain → event emitted
  2. An off-chain indexer/relayer picks up the event and calls the provider's API
  3. The relayer submits the provider's response back on-chain via record_coverage_response

This keeps the contract trustless (only authorized oracles/admin can record responses) while enabling real-world API connectivity.

Changes

contracts/insurance/src/types.rs

  • CoverageRequestStatus: Pending / Confirmed / Declined / Cancelled
  • ExternalProvider: id, name, api_endpoint, supported_coverage_types, is_active, registered_at
  • ExternalCoverageRequest: request details + provider quote, reference, and response timestamp

contracts/insurance/src/errors.rs

  • ProviderNotFound, ProviderInactive, CoverageRequestNotFound, CoverageRequestNotPending, UnsupportedCoverageType

contracts/insurance/src/lib.rs

Storage, events, and messages:

Message Who What
register_external_provider Admin Register a provider with name, API endpoint, supported types
deactivate_external_provider Admin Disable a provider
request_external_coverage Policyholder Request hybrid coverage for an active policy
record_coverage_response Admin/Oracle Record provider's confirm/decline response
cancel_coverage_request Requester/Admin Cancel a pending request
get_external_provider Anyone Query provider by ID
get_coverage_request Anyone Query request by ID
get_policy_coverage_requests Anyone All request IDs for a policy
get_provider_count Anyone Total registered providers

contracts/insurance/src/tests.rs

13 unit tests covering: registration (happy path, unauthorized), deactivation, coverage requests (happy path, non-policyholder, inactive provider, unsupported type), response recording (confirmed, declined, unauthorized, duplicate), cancellation (happy path, non-requester), and authorized oracle recording.

Closes #250

Implement on-chain registry and hybrid coverage request flow for
connecting PropChain policies to traditional insurance companies.

Changes:
- types.rs: CoverageRequestStatus (Pending/Confirmed/Declined/Cancelled),
  ExternalProvider (id, name, api_endpoint, supported_coverage_types,
  is_active), ExternalCoverageRequest (request + provider response fields)
- errors.rs: ProviderNotFound, ProviderInactive, CoverageRequestNotFound,
  CoverageRequestNotPending, UnsupportedCoverageType
- lib.rs: storage fields, ProviderRegistered/CoverageRequested/
  CoverageResponseRecorded events, and messages:
  register_external_provider, deactivate_external_provider,
  request_external_coverage, record_coverage_response,
  cancel_coverage_request, get_external_provider, get_coverage_request,
  get_policy_coverage_requests, get_provider_count
- tests.rs: 13 unit tests covering registration, deactivation, request
  creation, response recording (confirm/decline), cancellation, and
  all error paths

Closes MettaChain#250
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 29, 2026

@Nuel-ship-it Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@LaGodxy LaGodxy merged commit b3bd9a4 into MettaChain:main Apr 29, 2026
8 of 10 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.

Insurance: Integrate with external insurance providers

2 participants