JackpotRandomTicketBuyer

Lightweight helper contract for purchasing randomly-generated tickets. Simplifies the process of buying tickets with random number selections.

State Variables

Variable
Type
Description

jackpot

IJackpot

Immutable reference to Jackpot contract

usdc

IERC20

Immutable USDC token reference

nonce

uint256

Per-call nonce for randomness uniqueness

Events

RandomTicketsBought

event RandomTicketsBought(
    address indexed recipient,
    uint256 indexed drawingId,
    uint256 count,
    uint256 cost,
    uint256[] ticketIds
);

Functions

buyTickets

Purchase a specified number of randomly-generated tickets.

Parameters:

Name
Type
Description

_count

uint256

Number of random tickets to purchase

_recipient

address

Address to receive the ticket NFTs

_referrers

address[]

Referrer addresses for fee sharing

_referralSplitBps

uint256[]

PRECISE_UNIT-scaled weights (sum to 1e18)

_source

bytes32

Source identifier for tracking

Returns:

Type
Description

uint256[]

Array of minted ticket IDs

Requirements:

  • _count must be > 0

  • _recipient must not be zero address

  • Caller must have approved sufficient USDC

Example:

With Referrers

How Randomness Works

The contract uses on-chain entropy sources to generate random ticket numbers:

  1. Entropy Sources: Combines prevrandao, previous block hash, and a per-call nonce

  2. Unique Generation: Nonce increments each call to prevent same-block collisions

  3. Valid Tickets: All generated tickets have valid, unique normal numbers and valid bonusballs

Security Note

The randomness is suitable for ticket generation but not cryptographically secure. The final drawing uses Pyth Network entropy for provably fair winner selection.

Comparison with Other Purchase Methods

Method
Use Case
Ticket Selection

Jackpot.buyTickets

Direct purchase

User chooses numbers

JackpotRandomTicketBuyer

Quick random purchase

Auto-generated

BatchPurchaseFacilitator

Large orders

Mix of static + random

JackpotAutoSubscription

Recurring purchases

Mix of static + random

Integration Example

Last updated