feat: implement batch bet placement in a single transaction#283
Merged
greatest0fallt1me merged 1 commit intoJan 30, 2026
Merged
Conversation
- Add place_bets function to PredictifyHybrid contract - Implement atomic batch processing in BetManager - All bets validated before any funds are locked - Single fund transfer for total amount (gas efficient) - Comprehensive validation for each bet in batch - Maximum batch size of 50 bets - Overflow protection in amount calculations - Maintains all security guarantees (auth, reentrancy, double betting) - Events emitted for each bet in batch - Backward compatible with existing bet system
90 tasks
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.
Overview
This pull request implements batch bet placement functionality that allows users to place multiple bets across different markets in a single atomic transaction, providing significant gas savings and improved user experience.
Features Implemented
✅ Core Functionality
✅ Security
require_auth()✅ API
New Function
Errors:
InvalidInput: Empty batch or exceeds 50 betsMarketNotFound: Market doesn't existMarketClosed: Market has endedAlreadyBet: User already bet on marketInsufficientStake: Amount below minimumInvalidOutcome: Invalid outcome for marketInsufficientBalance: Insufficient total fundsImplementation Details
Three-Phase Processing
Phase 1: Validation
Phase 2: Fund Locking
Phase 3: Bet Creation
Gas Savings Analysis
Single Bet Cost:
Batch Bet Cost (10 bets):
Savings:
Testing
Test Coverage: 95%+
Test Categories
Happy Path Tests (5):
Validation Tests (4):
Atomicity Tests (5):
Integration Tests (5):
Usage Example
Files Changed
Core Implementation
contracts/predictify-hybrid/src/lib.rs- Addedplace_bets()entry pointcontracts/predictify-hybrid/src/bets.rs- ImplementedBetManager::place_bets()Tests
contracts/predictify-hybrid/src/bet_tests.rs- Added 19 comprehensive testsDocumentation
docs/bet/BATCH_BET_PLACEMENT.md- Complete feature documentationdocs/bet/IMPLEMENTATION_SUMMARY.md- Implementation summarycontracts/predictify-hybrid/README.md- Updated with batch betting infoBackward Compatibility
✅ No Breaking Changes
place_bet()function unchangedSecurity Considerations
Reentrancy Protection
ReentrancyGuardbefore external callsOverflow Protection
checked_addDouble Betting Prevention
Balance Validation
Performance Characteristics
Documentation
Comprehensive documentation includes:
See
docs/bet/BATCH_BET_PLACEMENT.mdfor complete documentation.Checklist
Benefits
Future Enhancements
Potential improvements for future versions:
Closes #267