TicketAutoCompoundVault

Contract Address: 0x3E22Ea60A1206A4BfEefBCff04D5E9d0A2D9B3Fcarrow-up-right

Enables users to automatically reinvest winning ticket prizes into new random tickets. Deposit winning tickets and compound winnings into new entries in a single transaction.

Overview

The vault streamlines the reinvestment flow:

  1. User approves the vault once via setApprovalForAll

  2. User calls depositAndCompound with winning ticket IDs

  3. Vault transfers tickets, claims winnings, and purchases new random tickets

  4. Any remainder (less than one ticket's price) is stored for the next compound

This is ideal for third-party integrations that want to offer users a "reinvest winnings" feature without requiring multiple transactions.

circle-info

For a complete integration guide with pre-flight validation checks, see Add Megapot to Your Site - Auto-Compound Winnings.

State Variables

Variable
Type
Description

jackpot

IJackpot

Immutable reference to Jackpot contract

jackpotNFT

IJackpotTicketNFT

Immutable reference to ticket NFT contract

usdc

IERC20

Immutable USDC token reference

batchFacilitator

IBatchPurchaseFacilitator

Batch facilitator for large orders

userPendingUSDC

mapping(address => uint256)

Accumulated USDC remainder per user

ticketPickerNonce

uint256

Nonce for random ticket generation

Events

Compounded

Emitted when a user successfully compounds winning tickets into new tickets.

Field
Description

user

Address that performed the compound

ticketsClaimed

Number of winning tickets deposited

usdcClaimed

Total USDC claimed from winnings

ticketsBought

Number of new tickets purchased

usdcSpent

USDC spent on new tickets

usdcRemaining

USDC stored for next compound

useBatchPurchase

Whether batch purchase was used (large orders)

referrers

Referrer addresses for the purchase

referralSplit

Fee split weights for referrers

Functions

depositAndCompound

Compound winning tickets into new random tickets in a single transaction.

Parameters:

Name
Type
Description

_ticketIds

uint256[]

Array of winning ticket IDs to compound

_referrers

address[]

Referrer addresses for fee sharing (can be empty)

_referralSplit

uint256[]

PRECISE_UNIT-scaled weights (must sum to 1e18 if non-empty)

Requirements:

  • User must have approved vault via jackpotNFT.setApprovalForAll(vaultAddress, true)

  • All tickets must be owned by the caller

  • At least one ticket must have winnings (from a completed drawing)

  • Jackpot must not be locked (drawing in progress)

  • User must not have an active batch order (if purchase would use batch path)

Example:

With Referrers:


getUserPendingUSDC

Get the pending USDC balance for a user (remainder from previous compounds).

Parameters:

Name
Type
Description

_user

address

Address to query

Returns:

Type
Description

uint256

Pending USDC balance (6 decimals)

Example:


Compound Flow

Purchase Paths

The vault automatically selects the optimal purchase path:

Scenario
Path
Execution

< 10 tickets

Direct via Jackpot.buyTickets

Immediate, tickets minted in same tx

>= 10 tickets

Via BatchPurchaseFacilitator

Queued, keepers execute over time

Pending USDC Accumulation

When winnings don't divide evenly by ticket price, the remainder accumulates:

Integration Guide

Setup (One-Time)

Before users can compound, they must approve the vault:

Finding Winning Tickets

Complete Compound Flow

Displaying Pending Balance

Error Handling

Error
Cause
Solution

EmptyTicketArray

Called with no ticket IDs

Provide at least one ticket ID

InvalidClaimedAmount

No tickets had winnings

Ensure tickets are winners from completed drawings

ActiveBatchOrderExists

User has pending batch order

Wait for batch order to complete or cancel it

JackpotLocked

Drawing is in progress

Wait for drawing to complete

NotTicketOwner

Caller doesn't own the tickets

Only compound your own tickets

TransferFromIncorrectOwner

NFT transfer failed

Ensure vault is approved via setApprovalForAll

Best Practices

  1. Batch old drawings: Compound tickets from multiple completed drawings at once to save gas

  2. Check active batch orders: Before compounding large amounts, verify the user doesn't have an active batch order

  3. Display pending balance: Show users their accumulated pending USDC so they understand the system

  4. Handle batch path: If useBatchPurchase is true, inform users their tickets will be minted by keepers (not immediately)

  5. Referrer integration: Pass your referrer address to earn fees on the new ticket purchases

Last updated