BatchPurchaseFacilitator

Enables bulk ticket purchases with a mix of user-defined static tickets and randomly-generated dynamic tickets. Orders are prepaid and executed by keepers.

State Variables

Variable
Type
Description

jackpot

IJackpot

Immutable reference to Jackpot contract

usdc

IERC20

Immutable USDC token reference

batchOrders

mapping(address => BatchOrder)

Active batch orders per user

staticTickets

mapping(address => Ticket[])

Static tickets per user

minimumTicketCount

uint256

Minimum tickets required per order

executionNonce

uint256

Nonce for dynamic ticket generation

Structs

BatchOrder

struct BatchOrder {
    uint256 orderDrawingId;      // Drawing this order was created for
    uint64 remainingUSDC;        // USDC balance for remaining tickets
    uint64 remainingTickets;     // Tickets still to be purchased
    uint64 totalTicketsOrdered;  // Original total ticket count
    uint64 dynamicTicketCount;   // Number of dynamic (random) tickets
    address[] referrers;         // Referrer addresses
    uint256[] referralSplit;     // PRECISE_UNIT-scaled weights
}

BatchOrderInfo

Enums

ExecutionAction

Events

BatchOrderCreated

BatchOrderCancelled

BatchOrderExecuted

Functions

createBatchOrder

Create a prepaid batch order for the current drawing.

Parameters:

Name
Type
Description

_recipient

address

Address to receive ticket NFTs

_dynamicTicketCount

uint64

Number of random tickets to generate

_userStaticTickets

Ticket[]

User-defined static tickets

_referrers

address[]

Referrer addresses for fee sharing

_referralSplit

uint256[]

PRECISE_UNIT-scaled weights (sum to 1e18)

Requirements:

  • Jackpot must be initialized and not locked

  • Recipient must not have an active order

  • Total tickets (dynamic + static) >= minimumTicketCount

  • Each static ticket must have valid numbers

  • Caller must have approved sufficient USDC

Example:


cancelBatchOrder

Cancel your active batch order and receive a refund.

Requirements:

  • Caller must have an active batch order

Example:


getBatchOrderInfo

Get batch order details for a user.

Parameters:

Name
Type
Description

_recipient

address

Address to query

Returns:

Type
Description

BatchOrderInfo

Order details and static tickets

Example:


hasActiveBatchOrder

Check if a recipient has an active batch order.

Parameters:

Name
Type
Description

_recipient

address

Address to check

Returns:

Type
Description

bool

True if active order exists

Example:


getBatchOrderActions

Get recommended actions for a batch of users (for keepers).

Parameters:

Name
Type
Description

_recipients

address[]

Addresses to evaluate

_maxTicketsPerBatch

uint256

Max tickets per execution call

Returns:

Type
Description

ExecutionAction[]

Recommended actions for each recipient

Batch Order Flow

  1. Create Order: User approves USDC and calls createBatchOrder

  2. Keeper Execution: Keepers call executeBatchOrder to process tickets

  3. Partial Execution: Large orders may be executed across multiple transactions

  4. Completion/Cancellation: Order completes when all tickets are bought or is cancelled

Cancellation Scenarios

Orders are automatically cancelled with full refund when:

  • Drawing is locked (drawing in progress)

  • Order was created for a previous drawing

  • Too many referrers (exceeds max allowed)

Users can manually cancel at any time before execution completes.

Last updated