feat(insurance-pool): add per-claim caps and cooldown windows - #23
Merged
Meshmulla merged 1 commit intoJul 28, 2026
Conversation
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
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.
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.PoolInfogains three new fields:max_claim_amount: i128— absolute per-claim cap (0disables it)max_claim_bps: u32— per-claim cap as a percentage oftotal_liquidity(0disables it)claim_cooldown_secs: u64— minimum seconds between claims from the same claimant on a pool (0disables it)create_poolseeds 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 existingset_risk_score/configure_governancepattern already used in this file.submit_claimnow enforces both caps and the cooldown before recording a claim, reverting with specific messages consistent with this file's existingpanic!-based error style (it doesn't use aResult/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 insoroban/src/rate_limiter.rs(a newDataKey::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 from8_000to10_000so 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— passescargo clippy --all-targets --all-features -- -D warnings— passes (no warnings)cargo build --release --target wasm32-unknown-unknown— passescargo test(full workspace) — all pass, 525 unit tests in the main lib (up from 517), including the 8 new insurance-pool tests; 0 failuresIssue
#10