DDAO-Lottery — a live, provably-fair on-chain lottery platform
Role: Full-stack developer, sole author — backend (704 commits / 843 all-branch) + the WalletConnect wallet frontend (175 commits) · Client: 3BUX LLC (Donkey DAO) Stack: AlgoKit-utils v8 · algosdk v3 · discord.js v14 · Express · Next.js 16 (WalletConnect wallet page + admin dashboard) · MongoDB + mongodb-memory-server · Redis · Tinyman SDK · Jest/Vitest · PM2 Live: testnet + mainnet (PM2) · wallet FE wallet-deploy-xi.vercel.app/connect · admin ddao-admin-deploy.vercel.app · API behind test-3.ghettopigeon.com · Timeline: Feb 2026 → present
The problem
DDAO-Lottery runs lotteries natively inside Discord, settling on Algorand. "A bot that picks a winner" undersells it badly — this is a financial system with money flowing through it continuously, and three things have to be true or the whole thing is worthless:
- Draws must be provably fair —
Math.random()deciding who wins real value is indefensible; players have to be able to verify the draw wasn't rigged. - The pot must always be solvent — the platform can never owe more than it actually holds, even across crashes, retries, and partial failures.
- The money math must be exact — floating-point rounding on token balances is a slow-motion disaster.
It started small (≈79 commits at an April snapshot) and has since grown roughly 9× to 704 backend commits (plus 175 on the WalletConnect frontend I also own) — a full-stack platform now shipped to mainnet as well as testnet.
Architecture
Three surfaces sit on one core: the Discord bot, a Next.js admin dashboard, and a WalletConnect wallet page — and the wallet frontend (Pera/Defly/Lute via use-wallet, multi-ticket signing, Tinyman swap/LP widgets, Vitest-tested) is my work too, making this a system I own top to bottom. Behind them, a custom 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 vrfSeed, vrfRound, and eligibleTicketIds, so any third party can reproduce the result from the public ledger after the fact — "trust me, it's random" doesn't fly when money is on the line. The Algorand Foundation Randomness Beacon (ECVRF; mainnet app 1615566206) is wired in as the committed upgrade path. Four lottery modes ride on this core — Weekly Payday, a Sniper Pot FOMO timer, a Mini-Jackpot with recursive redraws, and Flash Lotto — each with its own draw rules and NFT-based reward tiers.
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 (my most recent commit literally hardens this: "honor unbacked balance restorations in solvency check"). Treating solvency as an invariant the system actively enforces — rather than something you hope holds — is the difference between a lottery and an insolvency waiting to happen.
Exact money math. All balance arithmetic is BigInt-precision, eliminating floating-point drift on token amounts, with a weekly fee sweep and distribution that has to reconcile to the cent (well, the microAlgo).
One deployment, many guilds. The current multi-guild line lets a single deployment serve multiple Discord servers with isolation between them — a real multi-tenancy concern, not a toy.
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, with Jest coverage; money logic isn't trustworthy if it isn't deterministically tested. - Phased, documented rollout — a trail of handoff/spec docs (AlgoKit migration, VRF phases, fee-sweep phases, codebase-review findings) drives a staged testnet→mainnet path.
Results
- 704 backend commits (843 all-branch) + 175 frontend commits, sole author, Feb 2026 → today — live on testnet and mainnet.
- 29 models · ~101 endpoints · ~25 cron jobs, three deployables: Discord bot + REST API, Next.js admin, and the WalletConnect wallet page (mine).
- Commit-reveal provably-fair draws (reproducible from public block seeds), an enforced solvency invariant with hourly reconciliation, BigInt-exact accounting, and multi-guild Discord 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.