feat: per-user max bet cap#884
Open
Danielobito009 wants to merge 1 commit into
Open
Conversation
|
@Danielobito009 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Per-User Max Bet Cap
Issue
Closes #842
Description
This PR implements per-user, per-market maximum bet cap enforcement for the Predictify Hybrid prediction market contract. Users are now prevented from placing bets that cumulatively exceed a configured cap on any given market, whether in a single bet or across multiple bets.
Changes
Core Features
Modified Files
1.
contracts/predictify-hybrid/src/storage.rsAdded: 2 new
DataKeyvariants for persistent storage2.
contracts/predictify-hybrid/src/err.rsAdded: 3 new error codes
3.
contracts/predictify-hybrid/src/events.rsAdded:
MaxBetCapSetEventwith fieldscap: i128, timestamp: u64emit_max_bet_cap_set(env: &Env, cap: i128)4.
contracts/predictify-hybrid/src/bets.rsAdded: 5 new validator functions in
BetValidatorModified:
place_bet_inner()function5.
contracts/predictify-hybrid/src/bet_tests.rsAdded: 15 comprehensive tests covering:
Test Coverage:
Implementation Details
Security Guarantees
✅ Fail-Fast Validation - Cap check before any state mutation or fund transfer
✅ Arithmetic Safety - All i128 operations use
checked_add(), no panics on overflow✅ No Unsafe Patterns - No
unwrap()orexpect()in production paths✅ Admin Authentication -
require_auth()on all state-changing operations✅ Persistent State - User stakes survive ledger expiry (365-day TTL matches market TTL)
Cap Semantics
Validation Flow
Testing
Test Scenarios Covered
Configuration:
Tracking:
Single Bets:
Cumulative Bets:
Independence:
Running Tests
Expected Result: All 67 tests pass (52 existing + 15 new)
Usage Examples
Setting a Cap (Admin Only)
Checking Current Cap
User Bet Flow
Breaking Changes
None. This feature is backward compatible:
Deployment Considerations
Storage Impact
Gas Impact
Testing Before Mainnet
Files Changed Summary
Commit
Checklist
unwrap()orexpect()in production code