System Architecture & Specs
On this page (6 sections)
QanVault is designed as a modular, gas-efficient on-chain prize protocol on BNB Smart Chain. The protocol is powered by an O(1) batch range storage model, Chainlink VRF v2.5 verifiable entropy, and a strict 5-way segregated solvency framework.
1. Core Protocol Topology#
Player / Frontend UI
Direct configured QANX only; no swap or cross-chain purchase route
Configured ERC-20 QANX
Verify the token, vault, chain and ticket price before approving an allowance
QanVault.purchaseTickets
Exact token receipt and confirmed TicketsPurchased events establish issuance
QanVault (Configured Settlement Chain)
QanVault Liabilities
Token balance compared with pools, claims, reserves and fees
IRandomnessProvider
Chainlink VRF adapter with immutable explicit nativePayment billing mode
The architecture consists of four primary components:
QanVault Core Contract: Non-upgradeable EVM contract holding player balances, batch ranges, draw schedules, and non-custodial claim logic.
Chainlink VRF Provider: Deployment-pinned adapter communicating with the decentralized Chainlink VRF v2.5 coordinator network.
Canonical Settlement Token: Official BEP-20 / ERC-20
QANXtoken used for ticket purchases and direct prize claims.Decentralized Keepers & Client: Permissionless automated daemons executing period closures, VRF settlements, and 72-hour rollover maintenance.
2. O(1) Batch Range Storage & Logarithmic Resolution#
To eliminate the prohibitive gas costs of traditional on-chain lottery contracts (which mint and iterate individual NFTs or storage slots for every ticket), QanVault stores purchases as contiguous TicketBatch structures:
struct TicketBatch { uint256 startTicketId; uint256 endTicketId; address owner; uint64 purchaseTimestamp; uint32 dayId; uint32 weekId; uint32 monthId;}Architectural Benefits:
- Constant Gas Invariant: Writing a batch of 10,000 tickets requires only a single storage append (
ticketBatches.push), consuming the same negligible gas as a 1-ticket purchase (~1-3 Gwei). - Logarithmic $O(\log B)$ Owner Resolution: Winning tickets are resolved to their buyer's wallet address using binary search across
ticketBatchesviagetBatchForTicket(ticketId). - Contiguous Range Trackers: Active periods maintain start and end pointers in
dayTicketRanges,weekTicketRanges, andmonthTicketRanges.
3. Draw State Machine#
Draws transition through four explicit states during their lifecycle:
Tickets can be purchased; range records increment sequentially until 23:59:59 UTC cutoff.
Anyone closes an ended nonempty draw. Its pool and eligible count are fixed with one VRF request.
After original coordinator fulfillment, anyone can settle. No retry or cancellation exists; outages can lock the pool indefinitely.
Winning wallets claim before 72 hours from settlement. Expiry processing assigns 7.5% to Protocol Treasury and reserves the remainder for the following day.
| State | Transition Trigger | Operational Characteristics |
|---|---|---|
| Open | Period begins at UTC boundary | Purchases and claims active; range indices increment sequentially |
| RandomnessRequested | Period ends; closeDraw() executed | Draw frozen; vault pool and eligible count locked; VRF request dispatched |
| Settled | Chainlink VRF Coordinator fulfills seed | Sparse Fisher-Yates shuffle samples distinct winning tickets; 72-hour claim timer begins |
| Claimed / Rolled Over | Winning wallet claims or 72-hour deadline passes | Winning wallet receives QANX, or expireAndRollover() transfers 92.5% to future daily reserve |
4. Draw Settlement & Sparse Fisher-Yates Shuffle#
When Chainlink VRF fulfills the request with an unbiasable random seed, settleDraw() executes a sparse Fisher-Yates shuffle:
- Collision-Free Sampling: Guarantees distinct ticket indices without replacement.
- Constant Memory Footprint: Uses a sparse key-value map in memory rather than allocating large arrays, keeping settlement execution highly gas-efficient across all 10 daily winning tickets.
- Dust Management: Any fractional dust resulting from integer basis point division is automatically added to the Tier 1 Grand Prize.
5. Non-Custodial Claims & Solvency Proof#
Upon draw settlement, prize liabilities transition into totalClaimLiabilities. Winning wallets claim non-custodially via claimPrize(drawId, winnerIndex).
struct WinningSlot { uint256 ticketId; address winnerAddress; uint256 amount; PrizeStatus status; uint64 settledAt;}The fundamental solvency invariant guarantees full reserve backing at every block: