Skip to content

feat(insurance-pool): add per-claim caps and cooldown windows - #23

Merged
Meshmulla merged 1 commit into
stellar-kracken:mainfrom
priscaenoch:feature/10-insurance-pool-caps-cooldown
Jul 28, 2026
Merged

feat(insurance-pool): add per-claim caps and cooldown windows#23
Meshmulla merged 1 commit into
stellar-kracken:mainfrom
priscaenoch:feature/10-insurance-pool-caps-cooldown

Conversation

@priscaenoch

Copy link
Copy Markdown
Contributor

Summary

Closes #10

Adds configurable per-claim payout caps and a per-claimant cooldown to the insurance pool's claim flow (soroban/src/insurance_pool.rs), so a single large claim or a rapid series of claims from the same claimant can no longer drain a pool unchecked.

  • PoolInfo gains three new fields:

    • max_claim_amount: i128 — absolute per-claim cap (0 disables it)
    • max_claim_bps: u32 — per-claim cap as a percentage of total_liquidity (0 disables it)
    • claim_cooldown_secs: u64 — minimum seconds between claims from the same claimant on a pool (0 disables it)

    create_pool seeds new pools with protective defaults — 20% of the pool per claim, 1-day cooldown — so pools are safe out of the box without a redeploy, per the issue's note to keep these as tunable parameters with defaults.

  • New configure_claim_limits(pool_id, max_claim_amount, max_claim_bps, claim_cooldown_secs) admin-only entrypoint to tune (or disable) these per pool, mirroring the existing set_risk_score/configure_governance pattern already used in this file.

  • submit_claim now enforces both caps and the cooldown before recording a claim, reverting with specific messages consistent with this file's existing panic!-based error style (it doesn't use a Result/error-enum elsewhere, so I kept that convention rather than introducing a new one just for this):

    • "claim exceeds maximum claim amount"
    • "claim exceeds maximum claim percentage of pool"
    • "claim cooldown active"

    Cooldown tracking reuses the cooldown_until-timestamp pattern already established in soroban/src/rate_limiter.rs (a new DataKey::ClaimCooldown(Address, String) entry keyed per claimant per pool) rather than introducing separate timing logic, per the approach outlined in the issue thread.

  • One pre-existing test (test_fraudulent_claim_slashing) had its stake amount bumped from 8_000 to 10_000 so its claim continues to clear the new default 20% cap — that's the only change to existing code/tests; its actual behavior (fraud slashing) is unchanged.

  • Added 8 new tests covering the acceptance criteria: a claim landing exactly on the percentage-cap boundary (allowed), over-cap claims for both the absolute and percentage caps (reverting with the specific error), an admin widening the caps to allow a previously-rejected claim, a non-admin being rejected from configure_claim_limits, a repeat claim within the cooldown reverting, a repeat claim exactly at the cooldown boundary succeeding, and cooldowns being tracked per-claimant rather than globally.

Testing/validation performed

Run locally against a stable Rust toolchain matching CI:

  • cargo fmt --all -- --check — passes
  • cargo clippy --all-targets --all-features -- -D warnings — passes (no warnings)
  • cargo build --release --target wasm32-unknown-unknown — passes
  • cargo test (full workspace) — all pass, 525 unit tests in the main lib (up from 517), including the 8 new insurance-pool tests; 0 failures

Issue

#10

Adds configurable payout limits to the insurance pool claim flow so a
single large or rapid series of claims can't drain a pool:

- PoolInfo gains max_claim_amount (absolute cap, 0 disables), max_claim_bps
  (cap as a percentage of total_liquidity, 0 disables), and
  claim_cooldown_secs (minimum seconds between claims from the same
  claimant on a pool, 0 disables). create_pool seeds new pools with sane
  defaults (20% of pool per claim, 1-day cooldown) so protection is on by
  default without a redeploy; both caps may be tightened, loosened, or
  disabled independently via governance.
- New admin-only configure_claim_limits(pool_id, max_claim_amount,
  max_claim_bps, claim_cooldown_secs) entrypoint to tune these per pool,
  mirroring the existing set_risk_score/configure_governance pattern.
- submit_claim now enforces both caps (enforce_claim_caps) and the
  per-claimant cooldown (require_claim_cooldown_elapsed) before recording
  the claim, panicking with specific messages ("claim exceeds maximum
  claim amount", "claim exceeds maximum claim percentage of pool", "claim
  cooldown active") consistent with this file's existing panic!-based
  error style. Cooldown tracking reuses rate_limiter.rs's
  cooldown_until-timestamp pattern (a new DataKey::ClaimCooldown(Address,
  String) entry) rather than introducing separate timing logic.
- Bumped one pre-existing test's stake amount (8_000 -> 10_000) so its
  claim continues to clear the new default 20% cap; behavior of that test
  (fraud slashing) is otherwise unchanged.
- Added 8 new tests covering: a claim landing exactly on the percentage
  cap boundary, over-cap claims (both absolute and percentage) reverting
  with the specific error, an admin widening the caps to allow a
  previously-rejected claim, a non-admin being rejected from
  configure_claim_limits, a repeat claim within the cooldown reverting,
  a repeat claim exactly at the cooldown boundary succeeding, and
  cooldowns being tracked per-claimant rather than globally.

Closes stellar-kracken#10
@Meshmulla
Meshmulla merged commit 6678dbb into stellar-kracken:main Jul 28, 2026
2 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.

Add per-claim caps and cooldown windows to the insurance pool

2 participants