8000 GitHub - Tbelleng/Recent-work: Recent smart-contract in Cairo i did (have solidity version)
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Tbelleng/Recent-work

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Web3 Casino Dapp - Cairo Smart Contract Implementation

A modern Web3 casino platform built with Cairo smart contracts, featuring multiple games and secure token management.

Project Overview

This project implements a decentralized casino platform using Cairo smart contracts. It features multiple casino games, secure token management, and a robust controller system for managing game operations.

Project Structure

Core Components

  • src/ - Main source code directory
    • lib.cairo - Core library and entry point
    • token.cairo - Token contract implementation
    • controller/ - Game controller and management system
    • safe/ - Secure vault implementation for managing funds
    • games/ - Casino game implementations
      • base_game_interface.cairo - Base interface for all games
      • roulette/ - Roulette game implementation
      • coinflip/ - Coin flip game implementation
      • plinko/ - Plinko game implementation
      • crashgame/ - Crash game implementation

Testing and Scripts

  • tests/ - Test suite for all components
  • scripts/ - Deployment and utility scripts

Configuration

  • Scarb.toml - Project dependencies and configuration
  • snfoundry.toml - Foundry configuration for testing
  • Scarb.lock - Locked dependencies

Features

  • Multiple casino games (Roulette, Coin Flip, Plinko, Crash Game)
  • Secure token management system
  • Controller-based game management
  • Safe vault for fund management
  • Comprehensive test suite

Getting Started

  1. Install dependencies:
scarb build
  1. Run tests:
scarb test

Development

The project uses Cairo for smart contract development and includes a comprehensive test suite. Each game implements the base game interface, ensuring consistent behavior across all games.

License

This project is licensed under the terms included in the LICENSE file.

Security

The project implements various security measures:

  • Safe vault for fund management
  • Controller-based access control
  • Secure token management
  • Comprehensive testing

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Starkcrash Smart Contract

A Starknet smart contract implementation of a Crash Game where players can bet and attempt to cash out before the game crashes.

Overview

Starkcrash is a multiplayer betting game where players place bets during a betting phase and try to cash out during the playing phase before the game crashes. The crash point is determined by a provably fair random number system using commit-reveal scheme.

Game Flow

  1. Transition Phase: Initial state for a new game
  2. Committed Seed Phase: Operator commits a hashed seed for randomness
  3. Betting Phase: Players can place their bets
  4. Playing Phase: Game is live, multiplier increases, players can cash out
  5. Crashed Phase: Game ends, next game begins

Features

  • Provably fair randomness using commit-reveal scheme
  • Configurable casino fee (max 6%)
  • Adjustable maximum bet limits
  • Multiple bets per player allowed (configurable)
  • Pausable functionality for emergencies
  • Upgradeable design
  • ETH-based betting system

Core Functions

Player Functions

  • place_bet(game_id, amount): Place a bet during betting phase
  • get_player_bet(player, game_id): Query bet amount for a player
  • get_game_state(game_id): Check current game state

Operator Functions

  • commit_seed(seed_hash): Commit the seed hash for the next game
  • start_betting(): Open betting phase
  • start_game(): Start playing phase
  • end_game(seed): End game and reveal seed
  • process_cashout(game_id, player, multiplier): Process player cashout

Management Functions

  • set_max_bet(max_bet): Set maximum bet amount
  • set_min_bet(min_bet): Set minimum bet amount
  • set_casino_fee_basis_points(casino_fee_basis_points): Set casino fee (max 6%)
  • set_casino_address(casino_address): Set casino fee recipient
  • set_operator(operator): Set operator address
  • pause()/unpause(): Emergency pause/unpause

Events

  • BetPlaced: Emitted when a player places a bet
  • CashoutProcessed: Emitted when a player successfully cashes out
  • GameStarted: Emitted when a new game starts
  • GameEnded: Emitted when a game ends
  • CasinoCut: Emitted when casino fee is collected

Security Features

  • Ownership management using OpenZeppelin's Ownable pattern
  • Pausable functionality for emergency situations
  • Input validation for all parameters
  • Protection against multiple cashouts
  • Maximum bet limits
  • Casino fee capped at 6%

Dependencies

  • OpenZeppelin Contracts (Ownable, Pausable, Upgradeable)
  • Starknet Standard Library
  • Poseidon Hash function for commit-reveal scheme

Game Developer Guide

This section provides guidance for developers looking to implement new games that integrate with the casino's Controller and Safe contracts.

Architecture Overview

The casino platform consists of three main components:

  1. Safe Contract: Securely stores all casino funds and only accepts calls from the Controller
  2. Controller Contract: Manages game whitelisting, bet limits, and fee collection
  3. Game Contracts: Individual game implementations that interact with players and the Controller
Player → Game Contract → Controller Contract → Safe Contract

Implementing a New Game

To create a new game that integrates with the system, your contract should:

  1. Implement the required interfaces:

    • IBaseGame: Core game functionality
    • IGameManagement: Limit and configuration management
    • IGameLifecycle: Game state transitions
  2. Use standard storage patterns:

    • Map player bets by game_id and address: Map<(u64, ContractAddress), u256>
    • Track processed payouts: Map<(u64, ContractAddress), bool>
    • Store game states: Map<u64, GameState>
  3. Implement these key functions:

    • place_bet: Accept player funds and forward to Controller
    • process_cashout: Calculate winnings and request payout from Controller
    • Game state management (betting, playing, ended, etc.)

Integration with Controller

All financial operations must go through the Controller:

  1. Bet Processing:

    // In your place_bet function:
    let eth = ERC20ABIDispatcher { contract_address: ETH_ADDRESS.try_into().unwrap() };
    eth.transferFrom(player, self.controller_address.read(), amount);
    IControllerDispatcher { contract_address: self.controller_address.read() }.process_bet(amount);
  2. Cashout Processing:

    // In your process_cashout function:
    let payout = (bet_amount * multiplier) / 10000;
    IControllerDispatcher { contract_address: self.controller_address.read() }.process_cashout(player, payout);
  3. Game Limits:

    // For getting min/max bet limits:
    IControllerDispatcher { contract_address: self.controller_address.read() }.get_min_bet(get_contract_address());
    IControllerDispatcher { contract_address: self.controller_address.read() }.get_max_bet(get_contract_address());

Security Considerations

  1. Required Access Controls:

    • Use OpenZeppelin's Ownable for owner-only functions
    • Ensure only the owner can modify game parameters
    • Include Pausable functionality for emergency stops
  2. Critical Checks:

    • Validate bet amounts against min/max limits
    • Prevent duplicate processing of cashouts
    • Enforce game state transitions
    • Verify caller permissions for admin functions
  3. Funds Handling:

    • Never store or transfer ETH directly
    • Always route funds through the Controller
    • Verify all arithmetic to prevent over/underflows
    • USE BASIS POINTS

Testing Recommendations

  1. Create comprehensive tests covering:

    • Correct interaction with Controller
    • Proper game state transitions
    • Handling of edge cases (min/max bets, fee calculations)
    • Security scenarios (unauthorized access, invalid states)
  2. Use the provided test utilities in tests/utils.cairo for common setup

See the existing CrashGame implementation for a complete example of a game that integrates properly with the Controller and Safe contracts.

About

Recent smart-contract in Cairo i did (have solidity version)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0