From 64ab0b505f3d371f8303b48e2cefc68830229d9b Mon Sep 17 00:00:00 2001 From: martbost Date: Sat, 26 Sep 2026 15:36:25 -0500 Subject: [PATCH] docs: gamification expansion assessment against the live codebase Co-Authored-By: Claude Opus 5.5 --- docs/gamification-assessment-2026-09-26.md | 137 +++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 docs/gamification-assessment-2026-09-26.md diff --git a/docs/gamification-assessment-2026-09-26.md b/docs/gamification-assessment-2026-09-26.md new file mode 100644 index 0000000..14f0470 --- /dev/null +++ b/docs/gamification-assessment-2026-09-26.md @@ -0,0 +1,137 @@ +# PolHunter gamification expansion: architecture assessment + +Prepared 2026-09-26 against the live PolHunter codebase (`polhunter/`, deployed at polhunter.com) in response to the "Gamification Expansion Project Brief". Nothing has been built from the brief yet. Every "exists" below names the file it lives in. + +## Three corrections to the brief first + +1. **Hidden POL Hunt already exists.** It is how Code Hunt works today. The embed script on each advertiser site (`public/embed.js`) hides the hunter's code in one of N places on the page, chosen per hunter per day (`slotFor` in `lib/missions.js`). What the brief calls Hidden POL Hunt is a variant of this: a clickable token instead of a typed code. It is a small change, not a new system. +2. **The example fixed rewards are 20 to 60 times lower than today's rewards.** The brief suggests 0.002 to 0.006 POL per mission. Today's Code Hunt pays a weighted random 0.05 to 1 POL, averaging about **0.13 POL (about 1.5 cents)** per find, and hunters earn about 0.4 POL a day. Moving to 0.004 POL would cut hunter earnings by about 97% overnight. If rewards move to fixed amounts, they should sit near today's average (for example 0.10 to 0.30 POL depending on mission effort), not at the brief's examples. The brief itself says not to use its numbers without checking the economics, and this is why. +3. **Achievements cost almost nothing to expand, and existing progress is safe by design.** Badges are not stored. They are derived from the payout ledger on every request (`lib/social.js`: "All derived from the payout ledger; nothing new is stored"). New tiers (5 / 10 / 25 Full Sweeps, 7 / 14 / 30-day streaks, Explorer counts) compute from history the moment they ship, so existing hunters earn them retroactively for work already done, and nothing can be erased. + +## A. Current architecture + +| Piece | Where | How it works | +|---|---|---| +| Server | `server.js` (339 lines, plain Node `http`) | One process, JSON API plus static pages | +| Storage | `lib/store.js` | JSON files on a Docker volume (`missions`, `tokens`, `payouts`, `hunters`, `sessions`, `settings`...), atomic writes. No database | +| Sign-in | `lib/sso.js` | No sign-up on PolHunter. InstantAdPay signs a 5-minute single-use token (HMAC, shared secret); PolHunter turns it into a session carrying memberId, email, wallet, username, sponsorRef | +| Missions | `lib/missions.js` | `{ id, site, host, url, dwell, slots, active }`. Starting one issues a token (20-minute life). The 6-character code is HMAC(secret, token + member + mission), unique to that hunter and sitting | +| Proof | `public/embed.js` + `/api/embed/code` | The advertiser page runs the embed. It asks PolHunter for the code, which answers only if the request's Origin is the mission's own site and the dwell has passed since the token was issued | +| Rewards | `lib/rewards.js` | Weighted random draw 0.05 to 1 POL (log-scale, skewed low), 3 hunts a day, a 40 POL/day house cap; over-cap finds queue for the next day rather than being refused | +| Payment | `lib/faucet.js` | A dedicated hot wallet sends each drip as a real Polygon transaction. Everything before payment is off-chain | +| Leaderboards, badges, weekly prizes | `lib/social.js` | Derived from the ledger. 8 badges. Weekly prizes of 3 / 2 / 1 POL to the top three finders (minimum 10 finds) | +| Referrals | `lib/referrals.js` | Pays the referrer a flat bounty on the newcomer's first find, plus a 20% match for 30 days. Only for genuinely new members who came in through PolHunter (fail-closed) | +| Advertiser-funded missions | `lib/paid.js`, `lib/polusd.js` | Built, not deployed (tabled 2026-09-24): accounting and a solvency rule for missions paid by advertisers | +| Friday Bonus Hunts | `lib/fridaybank.js` | Live since 2026-09-26: extra Friday hunts banked by opening an inbox ad and watching a video on InstantAdPay | + +## B. Existing features to reuse + +- **Token + dwell + origin-locked proof** (`missions.js`, `embed.js`): the foundation for every visit-based mission type. Ad Detective, Clue Hunt, and Trail Hunt all start with this same "start mission, visit site, dwell" step. +- **Ledger-derived badges** (`social.js`): add achievement families by adding derivation rules, with no data migration. +- **Daily limit with allowances** (`rewards.daily`): already combines a base, paid-mission extras and Friday bonuses. A Mystery Box mission becomes one more allowance source. +- **House cap and queue** (`rewards.js`): every new paid-out mission type automatically respects the daily POL budget. +- **Signed server-to-server calls to InstantAdPay** (the `fridaybank` pattern): the template for granting ad credits and reporting advertiser analytics. +- **Referral qualification** (`referrals.js`): already pays on the newcomer's first find, not on sign-up. That is exactly the brief's "active referral" definition. The Recruiter badge already means "brought a hunter who found their first code". +- **Advertiser-paid missions** (`paid.js`): the solvency accounting for the brief's advertiser-funded hunts already exists. + +## C. Data changes (all additive) + +The JSON store means no migrations. Every change adds optional fields, and a missing field means today's behaviour: + +- `missions[]`: add `type` (missing = `'code'`), `reward.fixed` (a disclosed amount; missing = today's random draw), and for Ad Detective `questions: [{ q, options[], answer }]`. +- `tokens{}`: add `visitedAt`, set when the embed's origin-locked request succeeds after the dwell. This is the "they really were on the page" receipt that non-code missions need. +- `payouts[]`: add `missionType` (missing = `'code'`) and `boxId` where a mission came from a Mystery Box. Leaderboards and badges keep working because they already filter the ledger. +- New collection `boxes[]`: `{ id, memberId, day, earnedFor, openedAt, missionId, status }`. +- New collection `answers[]`: `{ memberId, missionId, questionId, correct, at }`, the source for advertiser analytics (correct-answer rate). + +## D. Mission engine + +A small registry keyed by mission type, each type supplying four functions: + +``` +start(member, mission) -> token and what the hunter is told +proof(token, request) -> what the embed or page returns (code, receipt, clue) +verify(token, submission)-> ok or a reason +reward(mission) -> fixed amount, or today's draw for legacy Code Hunt +``` + +Code Hunt is registered as the first type by wrapping today's `issue`, `codeForEmbed` and `check` unchanged. The routes `/api/my/start` and `/api/my/submit` stay the same and dispatch on `mission.type`, so existing links, tokens and embeds keep working. + +## E. Mystery Hunt Box + +- **Earned, not bought.** Phase 1 rule: finish the day's 3 Code Hunts and you get one box (one a day). Later: streak milestones and Full Sweeps. +- **Opening it reveals a mission, not an amount.** The box picks one mission from a pool (Phase 1: Ad Detective on the day's featured site) and shows its **fixed reward before the hunter starts**. That is the brief's key distinction, and it keeps boxes clear of prize-draw territory: the only chance element is which task you get, and every task pays the same disclosed rate for the same effort. +- **Does not use up the daily 3.** A box mission gets its own allowance, like the Friday bonus. +- **Paid from the same house cap** as finds, so it can never overspend. +- Storage: the `boxes` collection above. It is idempotent per member per day, so reopening or refreshing can't mint a second box. + +## F. Ad Detective + +1. The hunter opens the box, sees "Ad Detective on DripOffers, reward X POL", and presses Begin. A normal mission token is issued. +2. They visit the site. After the dwell, the embed's origin-locked call sets `visitedAt` on the token. No code is shown. +3. Back on the board, the question appears **only if `visitedAt` is set**. The options are shuffled per hunter, and the question is drawn from that site's pool (3 to 5 questions per site, admin-authored). +4. **One answer per mission.** Correct pays the disclosed reward; wrong records the attempt and pays nothing that day. +5. Every answer is logged to `answers[]` for the correct-rate figure advertisers will eventually see. + +**Phase 1 limit:** this needs the PolHunter embed on the advertiser's site to issue the visit receipt. All 8 current missions are our own properties, which already have it, so Phase 1 runs on those. External advertisers come later, with the embed in their campaign setup. + +## G. Anti-cheat + +Already in place: per-hunter HMAC codes (a shared code is useless to anyone else), origin lock, server-side dwell, 20-minute single-use tokens, rate limits (20 starts and 30 submits an hour), one PolHunter session per InstantAdPay account, InstantAdPay's one-account-per-person rules, the referral new-member floor, and the house cap. + +What new types add, and the defence for each: + +| Risk | Defence | +|---|---| +| Answering without visiting | The question only unlocks after the embed's visit receipt (origin-locked, after dwell) | +| Answer sharing in groups | A question pool per site, a per-hunter question and option order, one attempt | +| Scripted answering | The same token, dwell and rate limits as Code Hunt; answers arriving faster than a human could read get flagged | +| Replaying a receipt | Receipts are tied to one live token and one member, and a token is used once | +| Box farming | Boxes are earned only by finishing real hunts, one a day, idempotent per member | +| Timer manipulation | Dwell is measured on the server from when the token was issued, never by the browser | + +One weakness worth fixing along the way: dwell is measured from when the mission starts, not from time actually spent on the page. A hunter can start, leave the tab idle for the dwell, and come back. The embed could report visible time instead. That's a small improvement that helps every mission type. + +## H. InstantAdPay integration points + +- **Exists:** sign-in hand-off (`/api/my/polhunter`), the Friday bank check, the menu link back, and the done-for-today overlay. +- **New for ad-credit rewards:** a signed InstantAdPay endpoint that grants credits with a reason in the credit log and a per-event claim key (the `marks.js` pattern) so a retry can never pay twice. That unlocks "Full Sweep: + badge + ad credits". +- **Conversion message:** "You've hunted their ads. Now let them hunt yours." belongs on badge unlocks, the done-for-today overlay, and a card linking to InstantAdPay's campaign builder. +- **Later:** advertiser-bought hunt campaigns created inside InstantAdPay, funded through the existing `paid.js` accounting, with the analytics shown on the advertiser's campaign page. + +## I. Backward compatibility + +- Existing finds, POL totals, badges, leaderboards and referral relationships are untouched, because every change is additive and badges derive from the ledger. +- **Lucky Find** ("a drip of 0.4 POL or more") depends on the random draw. If Code Hunt ever moves to fixed rewards, the badge becomes unearnable. Keep it as a legacy badge: everyone who has it keeps it. +- **Weekly prizes** (3 / 2 / 1 POL to the top three finders) are an effort contest, not a draw. They fit the brief. Decide whether Detective completions count toward them. +- Missions with no `type` behave exactly as today, so a half-finished rollout can't break Code Hunt. + +## J. Phased plan + +**Phase 1 (small, testable): Ad Detective + Mystery Hunt Box** +- Mission `type` field, with Code Hunt wrapped as a type unchanged +- Visit receipt on tokens from the existing embed +- Ad Detective with an admin question bank for the 8 current sites +- Mystery Box: earned by finishing the day's 3 hunts, reveals Ad Detective, fixed disclosed reward, its own allowance, inside the house cap +- Detective badge family (Junior to Master), derived from the ledger +- Test: two internal accounts, one real day, then all hunters + +**Phase 2: achievement families + ad-credit rewards** +- Tiered Full Sweep, streak and Explorer badges (retroactive, derived) +- Signed InstantAdPay credit grants with an idempotency key +- Badges that also grant ad credits, plus the "now let them hunt yours" card + +**Phase 3: Clue Hunt, Trail Hunt, Hunting Party** +- Clue Hunt and Trail Hunt on the mission engine +- The Hunting Party progress card (registered / wallet linked / first find) on top of the existing referral data + +**Phase 4: decide on fixed rewards + advertiser-bought hunts** +- A deliberate decision on moving Code Hunt from random to fixed rewards, at a level close to today's ~0.13 POL average +- Advertiser-funded hunts sold through InstantAdPay (un-table `paid.js`), plus advertiser analytics: qualified visits, completions, correct-answer rate, engaged time + +**Later:** Ad Puzzle and Memory Hunt. They're worth doing, but they're the heaviest to build and the easiest to automate, so they come after the engine is proven. + +### Decisions needed from Marty before Phase 1 +1. The fixed reward for an Ad Detective completion (suggestion: about 0.15 POL, a little above a typical find, for more effort). +2. Who writes the 3 to 5 questions for each of the 8 sites (the AI can draft them from each site for approval). +3. Whether Detective completions count as finds for the weekly prizes and leaderboards.