Docs/Examples/Lottery Sweepstakes

LotterySweepstakes (Weekly VRF Draw)

A ticket-based weekly lottery where VRF picks one winner from a weighted pool — nobody should control when the draw runs.


Overview

LotterySweepstakes is a recurring lottery with proportional-ticket weighting. Players buy tickets at ticketPrice ETH each; more tickets = higher draw weight. On schedule, AutoLoop uses ECVRF to pick one winner proportionally, transfers the prize pool (minus fees), and resets for the next round.

PropertyValue
Base contractAutoLoopVRFCompatible
VRF usageWinner selection
Gas per tick~75k + 8k per entrant
Sourceautoloop/src/agents/LotterySweepstakes.sol
Tests22 passing (unit + fuzz)

Why AutoLoop + VRF Are Structurally Required

Inverted interest — identical to CrumbleCore but financial. With a deterministic draw, the trigger holder knows who wins before calling. They can hold the trigger until they've bought the winning block position, or sandwitch the call. More fundamentally: if the prize pool is large enough, nobody wants to trigger the draw for free — free-rider failure means the loop self-stalls without a neutral keeper.

Mechanics

  • Enter: buyTickets(count) at ticketPrice × count ETH. Calling again adds more tickets to the same address
  • shouldProgressLoop: returns true when entrantCount > 0 and roundInterval has elapsed since last draw
  • Winner selection: VRF-seeded linear scan through cumulative ticket weights picks one winner
  • Settlement: 3% protocol fee; prize = pool - fee transferred to winner. Round recorded in rounds[roundId]
  • Reset: all ticket counts and the entrants list are cleared after each draw — fresh start every round

Revenue Model

  • 3% protocol fee on each prize pool
  • AutoLoop gas fee per draw tick

Deploy

forge create src/agents/LotterySweepstakes.sol:LotterySweepstakes \
  --constructor-args 10000000000000000 604800 \
  --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast

Args: ticketPrice (wei), roundInterval (seconds). A 0.01 ETH ticket price and 7-day interval (604800) is typical.

Dashboard

View LotterySweepstakes on the AutoLoop Dashboard.