TicketAutoCompoundVault
Contract Address: 0x3E22Ea60A1206A4BfEefBCff04D5E9d0A2D9B3Fc
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:
User approves the vault once via
setApprovalForAllUser calls
depositAndCompoundwith winning ticket IDsVault transfers tickets, claims winnings, and purchases new random tickets
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.
For a complete integration guide with pre-flight validation checks, see Add Megapot to Your Site - Auto-Compound Winnings.
State Variables
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.
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:
_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:
_user
address
Address to query
Returns:
uint256
Pending USDC balance (6 decimals)
Example:
Compound Flow
Purchase Paths
The vault automatically selects the optimal purchase path:
< 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
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
Batch old drawings: Compound tickets from multiple completed drawings at once to save gas
Check active batch orders: Before compounding large amounts, verify the user doesn't have an active batch order
Display pending balance: Show users their accumulated pending USDC so they understand the system
Handle batch path: If
useBatchPurchaseis true, inform users their tickets will be minted by keepers (not immediately)Referrer integration: Pass your referrer address to earn fees on the new ticket purchases
Last updated

