Daily:
00h 00m 00s
Launch App
Technical Whitepaper & Smart Contracts

System Architecture & Specs

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#

Client Layer

Player / Frontend UI

Direct configured QANX only; no swap or cross-chain purchase route

Payment Authorization
Configured ERC-20 QANX

Verify the token, vault, chain and ticket price before approving an allowance

Ticket Issuance
QanVault.purchaseTickets

Exact token receipt and confirmed TicketsPurchased events establish issuance

Canonical Settlement Engine

QanVault (Configured Settlement Chain)

Contiguous Range Indexing
Draw State Transitions
Original VRF Request
Contract Accounting
QanVault Liabilities

Token balance compared with pools, claims, reserves and fees

Provably Fair Entropy
IRandomnessProvider

Chainlink VRF adapter with immutable explicit nativePayment billing mode

The architecture consists of four primary components:

  1. QanVault Core Contract: Non-upgradeable EVM contract holding player balances, batch ranges, draw schedules, and non-custodial claim logic.

  2. Chainlink VRF Provider: Deployment-pinned adapter communicating with the decentralized Chainlink VRF v2.5 coordinator network.

  3. Canonical Settlement Token: Official BEP-20 / ERC-20 QANX token used for ticket purchases and direct prize claims.

  4. 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:

solidity
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 ticketBatches via getBatchForTicket(ticketId).
  • Contiguous Range Trackers: Active periods maintain start and end pointers in dayTicketRanges, weekTicketRanges, and monthTicketRanges.

3. Draw State Machine#

Draws transition through four explicit states during their lifecycle:

Phase 1OPEN

Tickets can be purchased; range records increment sequentially until 23:59:59 UTC cutoff.

Phase 2RANDOMNESS REQUESTED

Anyone closes an ended nonempty draw. Its pool and eligible count are fixed with one VRF request.

Phase 3SETTLED

After original coordinator fulfillment, anyone can settle. No retry or cancellation exists; outages can lock the pool indefinitely.

Phase 4CLAIMED or ROLLED OVER

Winning wallets claim before 72 hours from settlement. Expiry processing assigns 7.5% to Protocol Treasury and reserves the remainder for the following day.

StateTransition TriggerOperational Characteristics
OpenPeriod begins at UTC boundaryPurchases and claims active; range indices increment sequentially
RandomnessRequestedPeriod ends; closeDraw() executedDraw frozen; vault pool and eligible count locked; VRF request dispatched
SettledChainlink VRF Coordinator fulfills seedSparse Fisher-Yates shuffle samples distinct winning tickets; 72-hour claim timer begins
Claimed / Rolled OverWinning wallet claims or 72-hour deadline passesWinning 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:

Winning Index r = i + ( keccak256(abi.encode(seed, i)) pmod{total - i} )
  • 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).

solidity
struct WinningSlot {
uint256 ticketId;
address winnerAddress;
uint256 amount;
PrizeStatus status;
uint64 settledAt;
}

The fundamental solvency invariant guarantees full reserve backing at every block:

Balance(Vault) ≥ totalUnsettledPools + totalClaimLiabilities + dailyRolloverReserve + weeklyRolloverReserve + monthlyRolloverReserve + accruedPlatformFees