Lottery
warning
These docs are for V1 of Eat The Pie, which is now deprecated. For the latest documentation for V2 on World Chain, please visit docs.eatthepie.xyz.
Github Link: https://github.com/eatthepie/contracts/blob/main/src/Lottery.sol
This contract implements the core features of the Eat The Pie lottery.
Key Features
- 🎟️ Multiple ticket purchase support (up to 100 tickets per transaction)
- 🔢 Three difficulty levels affecting number ranges (Easy, Medium, Hard)
- 🔐 Secure random number generation using VDFs and RANDAO
- 💰 Three-tiered prize system (Gold, Silver, Bronze)
- 🏆 NFT minting for jackpot winners
- 🔄 Automatic difficulty adjustment based on win patterns
- 💸 Configurable ticket pricing with scheduled changes
- 🛡️ Comprehensive security measures
- 💎 Prize pool management with excess handling
- 🔍 Detailed game information tracking and querying
Contract Structure
Inheritance
Ownable: Provides basic authorization control functionsReentrancyGuard: Prevents reentrant calls to functions
Dependencies
VDFPietrzak: Contract for VDF calculations and verificationNFTPrize: Contract for minting prize NFTsBigNumbers: Library for handling large number operations
Constants
BASIS_POINTS: 10000 (for percentage calculations)GOLD_PERCENTAGE: 6000 (60% of prize pool)SILVER_PLACE_PERCENTAGE: 2500 (25% of prize pool)BRONZE_PLACE_PERCENTAGE: 1400 (14% of prize pool)FEE_PERCENTAGE: 100 (1% of prize pool)FEE_MAX_IN_ETH: 100 ether- Difficulty-based number ranges:
- Easy: 1-50 (main), 1-5 (etherball)
- Medium: 1-100 (main), 1-10 (etherball)
- Hard: 1-150 (main), 1-15 (etherball)
DRAW_MIN_PRIZE_POOL: 500 etherDRAW_MIN_TIME_PERIOD: 1 weekDRAW_DELAY_SECURITY_BUFFER: 128 blocks
Key State Variables
currentGameNumber: Current game identifierticketPrice: Price of a single ticketlastDrawTime: Timestamp of the last drawconsecutiveJackpotGames: Counter for consecutive games with jackpot winnersconsecutiveNonJackpotGames: Counter for consecutive games without jackpot winners- Prize pool and game state mappings
- Winner tracking mappings for each prize tier
Core Functionality
Ticket Purchase
function buyTickets(uint256[4][] calldata tickets) external payable
- Allows purchase of up to 100 tickets in one transaction
- Each ticket requires 4 numbers (3 main numbers + 1 etherball)
- Automatically tracks tickets for all prize tiers
- Emits
TicketPurchasedandTicketsPurchasedevents
Drawing Process
- Draw Initiation
function initiateDraw() external
- Requires minimum prize pool (500 ETH)
- Requires minimum time period (1 week)
- Sets up security delay buffer
- Starts the next game
- Random Value Setting
function setRandom(uint256 gameNumber) external
- Uses Ethereum's block.prevrandao for randomness
- Must be called after security buffer period
- VDF Proof Submission
function submitVDFProof(uint256 gameNumber, BigNumber[] memory v, BigNumber memory y) external
- Verifies VDF proof by calling the VDF contract
- Generates final winning numbers
- Sets game status to completed
- Payout Calculation
function calculatePayouts(uint256 gameNumber) external
- Calculates prizes for each tier
- Handles excess fee management
- Transfers remaining prize pool to next game
- Emits payout information
Prize Claiming
function claimPrize(uint256 gameNumber) external
- Allows winners to claim their prizes
- Prevents double claiming
- Emits
PrizeClaimedevent
function mintWinningNFT(uint256 gameNumber) external
- Available only to gold tier winners
- Mints unique NFT by calling the NFT contract
- Emits
NFTMintedevent
Difficulty Management
function changeDifficulty() external
- Automatically adjusts difficulty based on win patterns
- Requires 3 consecutive games for adjustment
- Changes take effect on the next game
- Emits
DifficultyChangedevent
Administrative Functions
setTicketPrice: Schedules ticket price changessetNewVDFContract: Updates VDF contract with delaysetFeeRecipient: Updates fee recipient address
Query Functions
function getCurrentGameInfo() external view returns (
uint256 gameNumber,
Difficulty difficulty,
uint256 prizePool,
uint256 drawTime,
uint256 timeUntilDraw
)
function getBasicGameInfo(uint256 startGameId, uint256 endGameId) external view returns (GameBasicInfo[] memory)
function getDetailedGameInfo(uint256 gameId) external view returns (GameDetailedInfo memory)
function getUserGameWinnings(uint256 gameNumber, address user) external view
Events
TicketPurchased: Individual ticket purchase detailsTicketsPurchased: Bulk ticket purchase informationDrawInitiated: Start of drawing processRandomSet: Initial random value setVDFProofSubmitted: VDF verification completeWinningNumbersSet: Final winning numbersDifficultyChanged: Difficulty level updatesTicketPriceChangeScheduled: Future price changesExcessPrizePoolTransferred: Prize pool managementGamePrizePayoutInfo: Prize distribution detailsFeeRecipientChanged: Fee recipient updatesPrizeClaimed: Winner prize claimsNFTMinted: NFT prize creation