Skip to content

Add per-block bet-rate limiter to RateLimiter to dampen flash-trading bursts #659

Description

@greatest0fallt1me

Description

rate_limiter.rs enforces a per-user token bucket but does not bound aggregate per-ledger bet volume, leaving the market open to micro-burst manipulation right before resolution. Add a per_ledger_bet_cap enforced inside place_bet/place_bets so the global bet rate per ledger cannot exceed an admin-set ceiling.

Requirements and Context

  • New ledger-keyed counter under DataKey::PerLedgerBetCounter
  • Resets implicitly when ledger sequence advances
  • Configurable cap with sane default; admin-gated
  • Must be secure, tested, and documented
  • Should be efficient and easy to review

Suggested Execution

  1. Fork the repo and create a branch
    git checkout -b feature/per-ledger-bet-cap
  2. Implement changes
    • contracts/predictify-hybrid/src/rate_limiter.rs
    • contracts/predictify-hybrid/src/bets.rs
  3. Test and commit
    • cargo test -p predictify-hybrid per_ledger_bet_cap
    • Cover edge cases
    • Include test output and notes in the PR

Example commit message

feat: enforce per-ledger bet cap in RateLimiter

Acceptance Criteria

  • Cap is admin-set and read on every bet
  • Counter rolls over with ledger advancement
  • Bets above the cap fail with Error::PerLedgerBetCapExceeded

Guidelines

  • Validate auth, overflow, and storage TTL/archival
  • Clear documentation and inline comments
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GRANTFOX OSSGrantFox open-source campaign taskOFFICIAL CAMPAIGNOfficial GrantFox campaign issueStellar WaveIssues in the Stellar wave programenhancementNew feature or improvementrustRust implementationsmart-contractSoroban smart-contract worksorobanSoroban SDK / Stellar

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions