feat: implement minimum and maximum bet limits per event #278
+360
−42
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
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_betvalidates amounts and rejects out-of-range bets with clear errors.Changes
Types (
types.rs)BetLimits– Contract type withmin_betandmax_bet(i128).Storage & logic (
bets.rs)bet_limits_global; used when no per-event limits exist.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 withvalidate_bet_parameters(env, market_id, ...)using effective limits.InsufficientStake; above max →InvalidInput.Validation (
validation.rs)validate_bet_amount_against_limits(amount, limits)– Shared min/max check used by bets.Events (
events.rs)BetLimitsUpdatedEvent–admin,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 effectiveBetLimitsfor a market.Tests (
bet_tests.rs)Security
MIN_BET_AMOUNT..MAX_BET_AMOUNT).InsufficientStake,InvalidInput).Testing
cargo build– successcargo test– 419 passed (including 9 new bet-limits tests)stellar contract build --verbose– successCloses #243