Skip to content

Akshola00/issue10#23

Merged
tosoham merged 5 commits intoShonen-Labs:mainfrom
Akshola00:Akshola00/issue10
May 7, 2025
Merged

Akshola00/issue10#23
tosoham merged 5 commits intoShonen-Labs:mainfrom
Akshola00:Akshola00/issue10

Conversation

@Akshola00
Copy link
Contributor

PR: Implement Betting System for Starknet Combat Game

Overview

This PR implements a foundational betting system for our Starknet-based combat game. The system allows players to place bets on agents in battle rooms, resolve bets, and withdraw winnings. I've integrated OpenZeppelin contracts for security and standardization, leveraging their access control, ownership, and token components.

Implementation Details

Core Components Added

  1. Betting Contract (Betting.cairo):

    • Full implementation of betting functionality with room management, bet placement, and resolution
    • Integration with ERC20 tokens for bet payments
    • Security controls using OpenZeppelin's AccessControl and Ownable components
  2. STRK Token Implementation (strk.cairo):

    • Custom ERC20 token implementation for the betting system
    • Mint functionality for testing purposes
  3. Room Manager Improvements (RoomManager.cairo):

    • Code formatting and structural improvements
    • Better event emission handling
  4. Testing Framework:

    • Basic test setup for the betting contract

Key Functions Implemented

Betting Contract

  1. place_bet(room_id, agent_id, amount):

    • Allows players to place bets on specific agents in a battle room
    • Transfers ERC20 tokens from player to contract
    • Records player stake and agent selection
    • Validates room existence and bet amount
  2. resolve_bet(room_id, winner):

    • Admin-only function to set the winning agent for a room
    • Records the winner for withdrawal processing
  3. withdraw_winnings(room_id):

    • Allows winners to claim their winnings
    • Validates winner status before processing payment
    • Currently includes a placeholder bonus of 10 tokens
  4. create_game():

    • Admin-only function to create a new battle room
    • Returns the room ID for reference
    • Currently using placeholder agent IDs (24 and 66)
  5. set_winner(room_id, agent_id):

    • External function to set and emit the winning agent
    • Prevents double-resolution of rooms

STRK Token

  1. mint(recipient, amount):
    • Creates new tokens for a specified address
    • Used primarily for testing purposes

Configuration Updates

  • Added OpenZeppelin dependencies to Scarb.toml
  • Integrated with Starknet Foundry for testing

Future Implementations

  1. Betting Pool Mechanics:

    • Implement proportional reward distribution based on bet size and odds
    • Add handling for different betting scenarios (e.g., draws, multi-agent battles)
  2. Agent Creation System:

    • Replace placeholder agent IDs with dynamic agent creation/registration
    • Implement agent attributes and characteristics affecting odds
  3. Fee Structure:

    • Implement platform fees for bet placement and withdrawals
    • Add treasury management for collected fees
  4. Enhanced Security:

    • Add time-locked withdrawals
    • Implement emergency pause functionality
    • Add circuit breakers for large withdrawals
  5. Testing Expansion:

    • Comprehensive test suite for all betting scenarios
    • Fuzzing tests for security validation
    • Integration tests with frontend components
  6. Frontend Integration:

    • Add events and getters for frontend display of betting statistics
    • Implement user dashboard functionality

Technical Notes

  • The contract uses OpenZeppelin's component model for security and ownership
  • All token transfers are managed through proper approval and transfer mechanisms
  • The system is designed with modularity in mind for future extensions
  • Admin roles are used to control sensitive operations

This PR establishes the core betting infrastructure while setting the stage for more advanced features in subsequent development phases.

@vercel
Copy link

vercel bot commented May 6, 2025

@Akshola00 is attempting to deploy a commit to the poulavbhowmick03's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Akshola00
Copy link
Contributor Author

@tosoham ptak

@tosoham tosoham requested review from guha-rahul and tosoham May 7, 2025 09:20
upgrade version of scarb and snforge
Copy link
Contributor

@tosoham tosoham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test fails, Please fix it

@tosoham tosoham self-requested a review May 7, 2025 15:15
Copy link
Contributor

@tosoham tosoham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tosoham tosoham merged commit 56bcbe3 into Shonen-Labs:main May 7, 2025
0 of 2 checks 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.

2 participants

Comments