DDAO-Lottery
Live · Algorand mainnet- Role
- Full-stack — backend + wallet frontend + admin
- Timeline
- Feb 2026 → present
- Chain
- Algorand (mainnet)
- Scale
- 704 BE (843 all-branch) + 175 FE commits · 29 models · ~101 endpoints · ~25 crons
- Stack
- AlgoKit-utils v8 · algosdk v3 · discord.js v14 · Express · Next.js · MongoDB · Redis · Tinyman SDK · PM2
DDAO-Lottery is a provably-fair, multi-game lottery and rewards platform for the Donkey DAO ecosystem, played entirely through Discord and settling on Algorand. It runs four different lottery games, custodial player balances (deposit / withdraw / opt-in), a treasury that defends its own solvency, and a DeFi fee-flywheel that buys back $DDAO and provides Tinyman liquidity — on top of a stack of holder rewards. I built the whole thing: the backend, the WalletConnect wallet page (with swap / LP / staking widgets), and the admin dashboard.
The problem
Money runs through DDAO-Lottery non-stop — entries in, draws, payouts, fee sweeps, buybacks, liquidity. Three things have to be true or the whole thing is worthless:
- Draws must be provably fair. Picking winners with an ordinary server-side RNG is indefensible when real value is on the line — any player has to be able to verify, after the fact, that a draw wasn't rigged.
- The pot must always be solvent. The platform can never owe more than it actually holds — across crashes, retries, and partial failures.
- The money math must be exact. Floating-point rounding on token balances is a slow-motion disaster.
Architecture
Three surfaces sit on one core — the Discord bot, the WalletConnect wallet page, and the admin dashboard — and the wallet frontend is mine too (Pera/Defly/Lute via use-wallet, deposit/withdraw/opt-in, multi-ticket signing, Tinyman swap/LP/staking widgets, Vitest-tested). Behind them, a double-entry ledger in MongoDB is the auditable record of every entry, draw, and payout.
The hard decisions
Provably-fair draws via commit-reveal over Algorand block seeds. Winners aren't picked with a language RNG. The engine snapshots the confirmed tickets, commits to a future round, waits for it (~8 rounds, ~26s), then reads that block's seed and derives the winner deterministically: R = SHA-256(seed‖lotteryId‖drawId) → R mod n (or Fisher-Yates for multi-winner draws). Every draw persists its block seed, reveal round, and the exact eligible-ticket set, so any third party can reproduce the result from the public ledger. The Algorand Foundation Randomness Beacon (mainnet app 1615566206) is wired in as the committed upgrade path.
Four lottery games on one core. Weekly Payday (a scheduled raffle), a Sniper Pot (last-buyer / FOMO timer), a Mini-Jackpot (pick-numbers match with recursive redraws), and Flash Lotto (fast multi-winner) — each with its own draw rules and NFT-based reward tiers, all riding the same provably-fair engine and ledger.
A solvency invariant the system defends. The platform continuously checks that liabilities never exceed backing, and the audit can restore correct balances even when some are unbacked — treating solvency as an invariant the system actively enforces and self-heals, rather than something you hope holds.
Exact money math + a DAO flywheel. All balance arithmetic is BigInt-precision, eliminating floating-point drift on token amounts. A weekly fee sweep converts non-governance fees into a DDAO buyback plus single-asset Tinyman LP, with the rest split to leaderboard and NFT-holder rewards — a real treasury loop, reconciled to the microAlgo.
One deployment, many guilds. A multi-guild architecture lets a single deployment serve multiple Discord servers with per-guild scoping and isolation — real multi-tenancy, not a toy.
The reward surface
On top of the four games sit holder-reward systems: NFT-holder rewards, a volume leaderboard payout, LP-staking rewards, plus trait- and rarity-based reward tiers, with NFD names for display. The admin dashboard drives all of it — configuring games, pools, fees, and reward runs.
Engineering discipline
- Modern toolchain on purpose — AlgoKit-utils v8 + algosdk v3, the current Algorand Foundation stack.
- Deterministic tests —
mongodb-memory-serverruns the full entry-to-payout flow against a real in-memory MongoDB in CI; money logic isn't trustworthy if it isn't deterministically tested. - Phased, documented rollout — a trail of handoff/spec docs (AlgoKit migration, draw-engine phases, fee-sweep phases) drives a disciplined, staged rollout to its live mainnet deployment.
Results
- 704 backend commits (843 all-branch) + 175 wallet-frontend commits, sole author, Feb 2026 → today — live on its own Algorand mainnet server.
- 29 models · ~101 endpoints · ~25 cron jobs, three deployables: Discord bot + REST API, the Next.js wallet page, and the admin dashboard.
- Commit-reveal provably-fair draws (reproducible from public block seeds), four lottery games, an enforced solvency invariant with hourly reconciliation, BigInt-exact accounting, a Tinyman buyback/LP fee flywheel, and multi-guild deployment.
What this demonstrates
Building money-handling software to a real bar: verifiable fairness (commit-reveal over block seeds, reproducible by anyone), solvency invariants the system enforces and self-heals, exact financial arithmetic, deterministic testing of payout logic, and full-stack ownership through to a live mainnet deployment — exactly the discipline fintech and on-chain-settlement roles screen for.