Skip to content

[Smart Contract] Build Parametric Insurance Contract with Oracle Triggers#763

Open
Osifowora wants to merge 1 commit into
StellarDevHub:mainfrom
Osifowora:Build-Parametric-Insurance-Contract-with-Oracle-Triggers
Open

[Smart Contract] Build Parametric Insurance Contract with Oracle Triggers#763
Osifowora wants to merge 1 commit into
StellarDevHub:mainfrom
Osifowora:Build-Parametric-Insurance-Contract-with-Oracle-Triggers

Conversation

@Osifowora

Copy link
Copy Markdown

Summary

Build an automated parametric insurance contract that pays out automatically based on external data from an oracle feed. This is an MVP-critical feature for Web3 Student Lab's curriculum layer.

Changes

contracts/parametric_insurance/src/lib.rs

Complete rewrite with three core capabilities:

  1. Premium depositsbuy_policy() transfers tokens from buyer → contract via token::Client, matching the pattern established in lending.rs.

  2. Oracle trigger conditionspost_oracle_value() accepts numeric values per trigger key (e.g., temperature, rainfall, asset price). Each policy stores a trigger_value and trigger_above flag; claim() evaluates oracle_value >= trigger_value (above) or oracle_value <= trigger_value (below).

  3. Instant payouts — On successful claim, the payout is tracked as a claimable balance. withdraw_claim() transfers tokens from the contract to the buyer's address, completing the payout.

Capital Pool Management

  • Underwriters deposit tokens via underwrite() and withdraw excess capital via withdraw_underwriting(), both protected by solvency checks.
  • buy_policy() rejects if total_capital + premium < locked_liability + payout.
  • solvency_ratio_bps() reports pool health in basis points.

Testing

10 unit tests covering all paths and edge cases:

Test Scenario
buys_policy_and_claims_on_trigger Happy path: above-threshold trigger
rejects_claim_when_oracle_not_set No oracle value posted → error
rejects_claim_when_trigger_not_met_below Below-threshold policy, value above threshold → error
claims_when_trigger_below Happy path: below-threshold trigger
rejects_expired_policy Claim after expiry → error
prevents_double_claim Second claim → error
rejects_policy_that_would_break_solvency Insufficient pool → error
underwriter_can_withdraw Capital withdrawal with balance check
buyer_can_withdraw_claim Full cycle: deposit → buy → trigger → claim → withdraw
solvency_ratio_works Ratio before/after deposits

Acceptance Criteria Met

  • Oracle trigger events verify payouts instantly without manual claim approvals
  • Premium deposits from policyholders via token transfer
  • Trigger conditions fetched from trusted oracle feeds
  • Instant payouts to insured addresses when conditions are met

Technical Details

  • Language: Rust (Soroban SDK v22)
  • Token standard: Stellar Asset Contract (SAC) via token::Client
  • Oracle model: Single trusted oracle posts numeric values per trigger key
  • Error handling: panic_with_error! with typed InsuranceError enum
  • Patterns: Follows established codebase conventions from lending.rs, oracle_aggregator.rs, and state_channel.rs

Closes #718

…gers

Implement a fully-featured parametric insurance contract on Soroban that
accepts premium deposits, fetches trigger conditions from oracle feeds,
and executes instant payouts.

- Token-based premium deposits from policyholders via token::Client
- Numeric oracle value posting and threshold-based trigger evaluation
- Instant payout transfers to insured addresses on successful claim
- Capital pool management with underwriter deposits and withdrawals
- Solvency enforcement preventing over-leveraged policies
- 10 comprehensive tests covering all paths and edge cases

Closes StellarDevHub#718
@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

@Osifowora is attempting to deploy a commit to the Ayomide Adeniran's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 26, 2026

Copy link
Copy Markdown

@Osifowora 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

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.

[Smart Contract] Build Parametric Insurance Contract with Oracle Triggers

1 participant