Skip to content

Conversation

@Jagadeeshftw
Copy link
Contributor

Summary

Adds configurable minimum and maximum bet limits per event (or globally) so bets are bounded and markets stay fair and liquid. Admins can set global defaults or per-event limits; place_bet validates amounts and rejects out-of-range bets with clear errors.

Changes

Types (types.rs)

  • BetLimits – Contract type with min_bet and max_bet (i128).

Storage & logic (bets.rs)

  • Global limits – Stored under bet_limits_global; used when no per-event limits exist.
  • Per-event limits – Stored in a map keyed by market ID; override global for that market.
  • get_effective_bet_limits(env, market_id) – Resolves effective limits: per-event → global → default (MIN_BET_AMOUNT / MAX_BET_AMOUNT).
  • set_global_bet_limits / set_event_bet_limits – Validate bounds (min ≤ max, within absolute min/max), then store.
  • place_bet – Validates amount with validate_bet_parameters(env, market_id, ...) using effective limits.
  • Rejections: Below min → InsufficientStake; above max → InvalidInput.

Validation (validation.rs)

  • validate_bet_amount_against_limits(amount, limits) – Shared min/max check used by bets.

Events (events.rs)

  • BetLimitsUpdatedEventadmin, scope (market_id or "global"), min_bet, max_bet, timestamp.
  • emit_bet_limits_updated – Emitted when global or per-event limits are updated.

Public API (lib.rs)

  • set_global_bet_limits(env, admin, min_bet, max_bet) – Admin-only; sets global limits and emits event.
  • set_event_bet_limits(env, admin, market_id, min_bet, max_bet) – Admin-only; sets per-event limits and emits event.
  • get_effective_bet_limits(env, market_id) – Returns effective BetLimits for a market.

Tests (bet_tests.rs)

  • Set global limits and place at exactly min and exactly max.
  • Place below configured min / above configured max (expect panic with clear error).
  • Per-event limits override global; place at event min; place below event min (expect panic).
  • Unauthorized caller cannot set limits (expect panic).
  • Invalid bounds: min > max, min below absolute floor, max above absolute ceiling (expect panic).

Security

  • Only stored admin can set limits.
  • Limits are constrained to absolute bounds (MIN_BET_AMOUNT..MAX_BET_AMOUNT).
  • No new error enum variants (reuses InsufficientStake, InvalidInput).

Testing

  • cargo build – success
  • cargo test419 passed (including 9 new bet-limits tests)
  • stellar contract build --verbose – success

Closes #243

- Added functionality to set global and per-event bet limits, allowing admins to define minimum and maximum bet amounts.
- Introduced validation for bet limits to ensure they adhere to defined constraints.
- Implemented event emission for updates to bet limits, enhancing transparency.
- Added comprehensive tests to verify the correct behavior of bet limits and their enforcement in betting operations.
- Updated relevant modules to integrate new bet limits functionality and ensure compatibility with existing betting logic.
@greatest0fallt1me
Copy link
Contributor

LGTM!

@greatest0fallt1me greatest0fallt1me merged commit 509f8f9 into Predictify-org:master Jan 30, 2026
1 check 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.

feat: implement minimum and maximum bet limits per event

2 participants