diff --git a/lib/detective.js b/lib/detective.js index 67623e8..775a766 100644 --- a/lib/detective.js +++ b/lib/detective.js @@ -89,13 +89,16 @@ const closed = b => !!b && (b.status === 'won' || b.status === 'missed'); function putBox(b) { store.update('boxes', {}, all => { all[b.id] = b; return all; }); return b; } function patchBox(id, patch) { let out = null; store.update('boxes', {}, all => { if (all[id]) { Object.assign(all[id], patch); out = all[id]; } return all; }); return out; } -function earned(me) { const s = settings(); return s.on && rewards.findsToday(me.memberId, ctDay()) >= s.base; } +// The box is a Game Pass perk since 2026-11-02 (Marty: the Pass is the purchase that funds the game): a free account hunts +// once a day and never reaches the box; pass = false answers 'pass' on the board and refuses to open. +function earned(me, pass) { const s = settings(); return s.on && pass !== false && rewards.findsToday(me.memberId, ctDay()) >= s.base; } // what the board shows -function view(me) { +function view(me, pass) { const s = settings(); if (!s.on) return { on: false }; const day = ctDay(); const b = getBox(me.memberId, day); const done = rewards.findsToday(me.memberId, day); + if (!b && pass === false) return { on: true, status: 'pass', need: s.base, done: Math.min(done, s.base), pol: s.pol }; if (!b) return { on: true, status: done >= s.base ? 'ready' : 'locked', need: s.base, done: Math.min(done, s.base), pol: s.pol }; const m = missions.get(b.missionId) || {}; const q = bank().find(x => x.id === b.qid); const out = { on: true, status: b.status, pol: b.pol, site: m.site || b.missionId, name: m.name || '', dwell: m.dwell || 30, url: b.url || null, expires: b.exp || null }; @@ -108,11 +111,13 @@ function view(me) { } // pass = the Game Pass perk (GAME-PASS.md 4): a second case a day once the first is closed; the first case stays the rule for everyone else -function open(me, pass) { - if (!earned(me)) return { error: 'Finish today’s Code Hunts first. The box unlocks when your last one is found.' }; +// pass = the second-case perk; allowed = may a box open at all (the full tier: Game Pass holders, or everyone while GAMEPASS is off) +function open(me, pass, allowed) { const day = ctDay(); const cur = getBox(me.memberId, day); const second = !!(pass && cur && closed(cur) && !/:2$/.test(cur.id)); - if (cur && !second) return { ok: true, box: cur }; + if (cur && !second) return { ok: true, box: cur }; // a box already open today stays reachable (a pass that lapsed mid-day) + if (allowed === false) return { error: 'The Mystery Hunt Box opens for Game Pass holders.' }; + if (!earned(me, true)) return { error: 'Finish today’s Code Hunts first. The box unlocks when your last one is found.' }; const c = pickCase(me.memberId, day); if (!c) return { error: 'No cases are open right now. Check back tomorrow.' }; let made = null; // idempotent per member per day: a double tap or two tabs can never mint a second box diff --git a/lib/rewards.js b/lib/rewards.js index 3129869..2bece25 100644 --- a/lib/rewards.js +++ b/lib/rewards.js @@ -18,7 +18,10 @@ const { ctDay } = require('./missions'); // drawSkew k: log-uniform on u^(1/k), so k=1 is the plain log-uniform and k=3 leans hard to the floor // (mean ~0.13 POL on 0.05..1, one drip in eighty above 0.5). missionsPerDay: finds per hunter per // Central day (Marty, 2026-09-20: cap 40, k=3, 3 a day, so a launch morning does not empty the pool) -const DEFAULTS = { minPol: 0.05, maxPol: 1, dailyCapPol: 20, lowBalancePol: 40, drawSkew: 3, missionsPerDay: 3 }; +const DEFAULTS = { minPol: 0.05, maxPol: 1, dailyCapPol: 20, lowBalancePol: 40, drawSkew: 3, missionsPerDay: 3, + // the free tier (Marty 2026-11-02, every game must fund itself): a free account gets freeMissionsPerDay hunts drawn on + // freeMinPol..freeMaxPol; the full allotment and the full draw are for Game Pass holders (the Pass is the purchase) + freeMissionsPerDay: 1, freeMinPol: 0.02, freeMaxPol: 0.1 }; function settings() { return Object.assign({}, DEFAULTS, store.read('settings', {})); } function setSettings(patch) { return store.update('settings', {}, s => Object.assign(s, patch)); } @@ -36,7 +39,7 @@ function draw(min, max, skew) { // returned 0 for everyone, which would read as "no finds yet" to any new caller function findsToday(memberId, day) { const d = day || ctDay(); return store.read('payouts', []).filter(p => p.memberId === Number(memberId) && p.day === d && p.status !== 'failed' && !p.prize && !p.ref && !p.detective).length; } // passExtra: the Game Pass perk, +2 missions a day while the member's pass is active (GAME-PASS.md 4: 3 -> 5); 0 otherwise -function daily(memberId, doneIds, bonus, passExtra) { const s = settings(); const base = Math.max(1, Number(s.missionsPerDay) || 3); +function daily(memberId, doneIds, bonus, passExtra, pass) { const s = settings(); const base = pass ? Math.max(1, Number(s.missionsPerDay) || 3) : Math.max(1, Number(s.freeMissionsPerDay) || 1); // free tier since 2026-11-02 // every live paid mission this hunter has not done yet adds one, because the company is not // funding that completion let extra = 0; try { extra = require('./paid').extraAllowance(doneIds); } catch (e) {} @@ -44,7 +47,8 @@ function daily(memberId, doneIds, bonus, passExtra) { const s = settings(); cons const fb = Math.max(0, Number(bonus) || 0), pe = Math.max(0, Number(passExtra) || 0); const limit = base + extra + fb + pe; const done = findsToday(memberId, ctDay()); return { limit, done, left: Math.max(0, limit - done), base, friday: fb, pass: pe }; } // the nominal amount a completion of `mission` would pay (the Game Pass asks InstantAdPay about it before grant() records it) -function quote(mission) { const s = settings(); return mission.paid ? Math.round(Number(mission.hunterPol || 0) * 10000) / 10000 : draw(Number(s.minPol), Number(s.maxPol)); } +function quote(mission, pass) { const s = settings(); if (mission.paid) return Math.round(Number(mission.hunterPol || 0) * 10000) / 10000; // an advertiser-funded find pays what the advertiser set, every tier + return pass ? draw(Number(s.minPol), Number(s.maxPol)) : draw(Number(s.freeMinPol), Number(s.freeMaxPol)); } // the free draw since 2026-11-02 // What the COMPANY has spent today. Advertiser-funded completions are excluded on purpose: the // hunter is paid out of what the advertiser already put in the faucet, so counting it here would // let a paid mission use up the house budget (Marty, 2026-09-24). @@ -74,7 +78,7 @@ function grant(member, mission, opts) { // An advertiser-funded mission pays exactly what the advertiser set, every time. No draw, so // the reserve taken at purchase is exact and can never come up short. const isPaid = !!mission.paid; - const pol = opts.pol != null ? Math.round(Number(opts.pol) * 10000) / 10000 : quote(mission); + const pol = opts.pol != null ? Math.round(Number(opts.pol) * 10000) / 10000 : quote(mission, !!opts.pass); const day = ctDay(); const budgetLeft = mission.budget ? mission.budget - store.read('payouts', []).filter(p => p.missionId === mission.id && p.status !== 'failed').length : Infinity; if (budgetLeft <= 0) return { error: 'This mission has paid out all it was funded for.' }; diff --git a/lib/social.js b/lib/social.js index 4a8cd8d..73eb3a3 100644 --- a/lib/social.js +++ b/lib/social.js @@ -101,7 +101,9 @@ function awardWeek(monday) { const done = store.read('prizes', []); if (done.some(x => x.week === monday)) return { skipped: 'already awarded', week: monday }; const rules = prizeRules(); - const winners = weekRows(monday).filter(r => r.finds >= rules.minFinds).slice(0, rules.pol.length).map((r, i) => Object.assign({ rank: i + 1, prizePol: rules.pol[i] }, r)); + // weekly prizes are for Game Pass holders (Marty 2026-11-02: the Pass is the purchase that funds the game); with GAMEPASS off, everyone qualifies as before + let passOk = () => true; try { const gp = require('./polgrant'); if (gp.on && gp.on()) passOk = r => { try { return !!gp.passOf(r.memberId, r.email).active; } catch (e) { return false; } }; } catch (e) {} + const winners = weekRows(monday).filter(r => r.finds >= rules.minFinds && passOk(r)).slice(0, rules.pol.length).map((r, i) => Object.assign({ rank: i + 1, prizePol: rules.pol[i] }, r)); const day = ctDay(), at = Date.now(); const recs = winners.map(w => ({ id: 'prize' + monday.replace(/-/g, '') + '-' + w.rank, memberId: w.memberId, email: w.email, wallet: w.wallet, username: w.username, missionId: 'prize:' + monday, site: 'Weekly prize #' + w.rank, pol: w.prizePol, day, at, status: 'due', tx: null, paidAt: null, error: null, prize: { week: monday, rank: w.rank } })); if (recs.length) store.update('payouts', [], all => { all.push(...recs); return all; }); diff --git a/public/app.js b/public/app.js index 31e0616..77cf68b 100644 --- a/public/app.js +++ b/public/app.js @@ -220,7 +220,8 @@ const head = t => '
One answer only. Look carefully before answering.
'; let h = ''; - if (bx.status === 'locked') h = head('Unlocks when today’s hunts are done') + 'Find all ' + bx.need + ' of today’s codes and your box opens: a bonus case worth a fixed ' + pol + '. ' + bx.done + ' of ' + bx.need + ' found.
'; + if (bx.status === 'pass') h = head('A Game Pass perk') + 'Game Pass holders hunt five codes a day at the full reward, and their box opens after the last one with a bonus case worth a fixed ' + pol + '. Get the Game Pass on InstantAdPay.
'; + else if (bx.status === 'locked') h = head('Unlocks when today’s hunts are done') + 'Find all ' + bx.need + ' of today’s codes and your box opens: a bonus case worth a fixed ' + pol + '. ' + bx.done + ' of ' + bx.need + ' found.
'; else if (bx.status === 'ready') h = head('Your box is ready') + 'Open it to see today’s bonus case. It pays a fixed ' + pol + ' and does not use up a mission.
'; else if (bx.status === 'open') h = head('\u{1F50E} Ad Detective on ' + esc(bx.site)) + 'Reward: ' + pol + ', fixed. Visit the site and look around for at least ' + bx.dwell + ' seconds. Then come back here and answer one question about what the site says.
' + rule + ''; else if (bx.status === 'started') { h = head('\u{1F50E} On the case: ' + esc(bx.site)) + 'Stay on the site tab for at least ' + bx.dwell + ' seconds and read what it says. A note on the page tells you when your visit is recorded. Your question appears here right after.
Open the site again ↗ · if the note never showed, press Begin again after this attempt times out.
' + (bx.expires && Date.now() > bx.expires ? '' : ''); boxPoll = setTimeout(boxRefresh, 6000); } diff --git a/server.js b/server.js index 7ae0360..20e620f 100644 --- a/server.js +++ b/server.js @@ -53,6 +53,10 @@ const IAP_URL = String(process.env.IAP_URL || 'https://instantadpay.com').replac gp.use({ game: 'polhunter', secret: String(process.env.HUNT_SSO_SECRET || '').trim(), iap: IAP_URL, store, notify: (kind, p) => notify(kind, p) }); const passActive = me => !!(gp.on() && me && gp.passOf(me.memberId, me.email).active); const passExtra = me => passActive(me) ? 2 : 0; // the perk: 5 missions a day instead of 3 +// the full tier (Marty 2026-11-02): Game Pass holders get the full allotment, the full draw, the weekly prizes and the Mystery Box; +// a free account gets the free tier (lib/rewards.js freeMissionsPerDay / freeMinPol / freeMaxPol). With GAMEPASS off there is no +// pass to buy, so everyone stays on the full tier as before. +const fullTier = me => !gp.on() || passActive(me); // one reward through IAP: ask(pol, ref) -> IAP's answer (+ the player-facing note), wait(rowId, pol, ref) -> queue the ref (fail closed) const gpGate = me => ({ ask: async (pol, ref) => { const r = await gp.grant({ memberId: me.memberId, email: me.email, kind: 'daily', pol, ref }); r.note = gp.note(r, 'daily', pol); return r; }, @@ -124,7 +128,7 @@ async function postBadge(p) { return false; } // Marty's rule (2026-09-19): when the day's pool is spent, say so; claims reopen at midnight Central -const dailyMsg = d => 'That is your ' + (['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight'][d.limit] || d.limit) + ' for today. Fresh missions at midnight Central.'; +const dailyMsg = d => 'That is your ' + (['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight'][d.limit] || d.limit) + ' for today. Fresh missions at midnight Central.' + (d.pass ? '' : ' Game Pass holders hunt five a day at the full reward.'); // free tier since 2026-11-02 const SPENT_MSG = 'Today\u2019s POL pool is spent. No more claims today. Claims reopen at midnight Central.'; function refOf(req) { const m = /(?:^|;\s*)ph\.ref=([^;]+)/.exec(req.headers.cookie || ''); const r = m ? decodeURIComponent(m[1]) : ''; return /^[A-Za-z0-9_.-]{1,40}$/.test(r) ? r : null; } function explorer() { return Number(process.env.HUNT_CHAIN_ID) === 80002 ? 'https://amoy.polygonscan.com' : 'https://polygonscan.com'; } @@ -279,14 +283,14 @@ const server = http.createServer(async (req, res) => { return json(res, 200, { me: { memberId: me.memberId, username: me.username, wallet: me.wallet }, missions: missions.forMember(me.memberId).map(m => Object.assign(pubMission(m), { done: done.has(m.id) || wdone.has(m.id) })), drips: rewards.mine(me.memberId).slice(0, 20), faucet: { on: faucetOn }, pool: rewards.pool(), daily: rewards.daily(me.memberId, rewards.doneToday(me.memberId, me.wallet), fbank.bonus, passExtra(me)), fridayBank: fbank, gamepass: gp.view(me.memberId, me.email), badges: social.badgesFor(me.memberId), badgeCards: (() => { const got = new Set(social.badgesFor(me.memberId).map(b => b.id)); const who = social.nameOf(me); return social.BADGES.map(b => ({ id: b.id, name: b.name, icon: b.icon, why: b.why, art: '/badges/badge-' + b.id + '.jpg', earned: got.has(b.id), page: got.has(b.id) ? SITE + '/b/' + who + '/' + b.id : null, image: got.has(b.id) ? SITE + '/badge-img/' + who + '/' + b.id + '.jpg' : null })); })(), rank: { week: social.rankOf(me.memberId, 'week'), month: social.rankOf(me.memberId, 'month'), all: social.rankOf(me.memberId, 'all') }, share: { link: social.shareLink(SITE, me), joinUrl: 'https://instantadpay.com/join/' + encodeURIComponent(String(me.username || me.memberId)) + '?from=polhunter' }, - referral: referrals.state(me), box: detective.view(me) }); + referral: referrals.state(me), box: detective.view(me, fullTier(me)) }); } if (p === '/api/my/start' && req.method === 'POST') { const b = await readBody(req); const m = missions.get(String(b.missionId || '')); if (!m || !m.active) return json(res, 404, { error: 'That mission is not open.' }); if (!me.wallet) return json(res, 400, { error: 'Link a wallet on InstantAdPay first so the drip has somewhere to land, then open PolHunter again.' }); if (rewards.completed(me.memberId, m.id, me.wallet)) return json(res, 400, { error: 'You already completed this one.' }); { const pool = rewards.pool(); if (pool.spent) return json(res, 400, { error: SPENT_MSG, spent: true, resetsAt: pool.resetsAt }); } - { const fb = await fbFor(me); const d = rewards.daily(me.memberId, rewards.doneToday(me.memberId, me.wallet), fb.bonus, passExtra(me)); if (!d.left) return json(res, 400, { error: dailyMsg(d), dailyDone: true, resetsAt: rewards.pool().resetsAt }); } + { const fb = await fbFor(me); const d = rewards.daily(me.memberId, rewards.doneToday(me.memberId, me.wallet), fb.bonus, passExtra(me), fullTier(me)); if (!d.left) return json(res, 400, { error: dailyMsg(d), dailyDone: true, resetsAt: rewards.pool().resetsAt }); } if (limited('start:' + me.memberId, 20, 3600000)) return json(res, 429, { error: 'Easy. Twenty starts an hour is plenty.' }); const t = missions.issue(me.memberId, m.id); // a mission URL may place the token itself with {token} (a Telegram Mini App takes it in @@ -302,14 +306,14 @@ const server = http.createServer(async (req, res) => { const m = missions.get(c.rec.missionId); if (!m) return json(res, 404, { error: 'That mission is gone.' }); if (rewards.completed(me.memberId, m.id, me.wallet)) return json(res, 400, { error: 'You already completed this one.' }); { const pool = rewards.pool(); if (pool.spent) return json(res, 400, { error: SPENT_MSG, spent: true, resetsAt: pool.resetsAt }); } - { const fb = await fbFor(me); const d = rewards.daily(me.memberId, rewards.doneToday(me.memberId, me.wallet), fb.bonus, passExtra(me)); if (!d.left) return json(res, 400, { error: dailyMsg(d), dailyDone: true, resetsAt: rewards.pool().resetsAt }); } + { const fb = await fbFor(me); const d = rewards.daily(me.memberId, rewards.doneToday(me.memberId, me.wallet), fb.bonus, passExtra(me), fullTier(me)); if (!d.left) return json(res, 400, { error: dailyMsg(d), dailyDone: true, resetsAt: rewards.pool().resetsAt }); } const before = new Set(social.badgesFor(me.memberId).map(b => b.id)); let g, note = null; if (gp.on() && !m.paid) { // the Game Pass: IAP's account-wide daily cap first (a paid mission is the advertiser's money, not gated) - const quote = rewards.quote(m), ref = 'find:' + m.id + ':' + missions.ctDay(), r = await gpGate(me).ask(quote, ref); note = r.note; + const quote = rewards.quote(m, fullTier(me)), ref = 'find:' + m.id + ':' + missions.ctDay(), r = await gpGate(me).ask(quote, ref); note = r.note; if (r.retry) { g = rewards.grant(me, m, { pol: quote, status: 'gp-wait', nominal: quote, gp: { ref, kind: 'daily', nominal: quote, pending: true } }); if (!g.error) gpGate(me).wait(g.rec.id, quote, ref); } else g = rewards.grant(me, m, { pol: r.allowed, nominal: quote, gp: { ref, kind: 'daily', nominal: quote, pass: !!r.pass, capHit: r.capHit || null } }); - } else g = rewards.grant(me, m); + } else g = rewards.grant(me, m, { pass: fullTier(me) }); if (g.error) return json(res, 400, g); // whoever brought this hunter gets paid for it: the bounty on their first find, a match while they are new let refDrips = []; @@ -322,7 +326,7 @@ const server = http.createServer(async (req, res) => { message: g.waiting ? 'Found it. ' + note : g.capped ? 'Found it. ' + note : g.queued ? 'Found it. Today’s POL is spoken for, so yours is queued and pays out next.' : 'Found it. ' + fmt(g.rec.pol) + ' POL is on its way to your wallet.' + (note ? ' ' + note : '') }); } // ---- Mystery Hunt Box + Ad Detective - if (p === '/api/my/box/open' && req.method === 'POST') { const r = detective.open(me, passActive(me)); return json(res, r.error ? 400 : 200, r.error ? r : { ok: true, box: detective.view(me) }); } // pass: a second case a day + if (p === '/api/my/box/open' && req.method === 'POST') { const r = detective.open(me, passActive(me), fullTier(me)); return json(res, r.error ? 400 : 200, r.error ? r : { ok: true, box: detective.view(me, fullTier(me)) }); } // pass: a second case a day if (p === '/api/my/box/start' && req.method === 'POST') { if (!me.wallet) return json(res, 400, { error: 'Link a wallet on InstantAdPay first so the reward has somewhere to land.' }); if (limited('boxstart:' + me.memberId, 20, 3600000)) return json(res, 429, { error: 'Easy. Try again in a little while.' }); @@ -336,7 +340,7 @@ const server = http.createServer(async (req, res) => { const unlocked = r.correct ? social.badgesFor(me.memberId).filter(x => !before.has(x.id)) : []; for (const x of unlocked) notify('badge', { me, id: x.id }).catch(() => {}); const msg = r.correct ? (r.queued ? 'Case solved. Today\u2019s POL is spoken for, so your ' + fmt(r.pol) + ' POL is queued and pays out next.' : 'Case solved. ' + fmt(r.pol) + ' POL is on its way to your wallet.') : 'Not this time. The answer was: ' + r.answer + '. A new box unlocks tomorrow.'; - return json(res, 200, { ok: true, correct: r.correct, pol: r.pol, nominal: r.nominal, queued: r.queued, capped: r.capped, waiting: r.waiting, note: r.note || null, unlocked: unlocked.map(x => x.id), message: msg + (r.note ? ' ' + r.note : ''), box: detective.view(me), gamepass: gp.view(me.memberId, me.email) }); + return json(res, 200, { ok: true, correct: r.correct, pol: r.pol, nominal: r.nominal, queued: r.queued, capped: r.capped, waiting: r.waiting, note: r.note || null, unlocked: unlocked.map(x => x.id), message: msg + (r.note ? ' ' + r.note : ''), box: detective.view(me, fullTier(me)), gamepass: gp.view(me.memberId, me.email) }); } return json(res, 404, { error: 'No such call.' }); } @@ -355,7 +359,7 @@ const server = http.createServer(async (req, res) => { return json(res, 200, { ok: true, missions: missions.list() }); } if (p === '/api/admin/mission' && req.method === 'DELETE') { const b = await readBody(req); missions.remove(String(b.id || '')); return json(res, 200, { ok: true, missions: missions.list() }); } - if (p === '/api/admin/settings' && req.method === 'POST') { const b = await readBody(req); const patch = {}; for (const k of ['minPol', 'maxPol', 'dailyCapPol', 'lowBalancePol', 'weeklyMinFinds', 'drawSkew', 'missionsPerDay', 'detectiveOn', 'detectivePol', 'refEnabled', 'refBountyPol', 'refMatchPct', 'refMatchDays', 'refNewDays', 'refCapPol', 'refMatchMinPol']) if (b[k] != null && Number(b[k]) >= 0) patch[k] = Number(b[k]); for (const k of ['weeklyPrizes', 'leaderboardExclude']) if (Array.isArray(b[k])) patch[k] = b[k].map(Number).filter(n => n >= 0); return json(res, 200, { ok: true, settings: rewards.setSettings(patch) }); } + if (p === '/api/admin/settings' && req.method === 'POST') { const b = await readBody(req); const patch = {}; for (const k of ['minPol', 'maxPol', 'dailyCapPol', 'lowBalancePol', 'weeklyMinFinds', 'drawSkew', 'missionsPerDay', 'freeMissionsPerDay', 'freeMinPol', 'freeMaxPol', 'detectiveOn', 'detectivePol', 'refEnabled', 'refBountyPol', 'refMatchPct', 'refMatchDays', 'refNewDays', 'refCapPol', 'refMatchMinPol']) if (b[k] != null && Number(b[k]) >= 0) patch[k] = Number(b[k]); for (const k of ['weeklyPrizes', 'leaderboardExclude']) if (Array.isArray(b[k])) patch[k] = b[k].map(Number).filter(n => n >= 0); return json(res, 200, { ok: true, settings: rewards.setSettings(patch) }); } // award a week by hand (its Monday key); already-awarded weeks are skipped if (p === '/api/admin/prizes/award' && req.method === 'POST') { const b = await readBody(req); const r = social.awardWeek(String(b.week || '')); if (r && r.winners && r.winners.length) notify('prize', r).catch(() => {}); return json(res, r && r.error ? 400 : 200, r); } // Ad Detective question bank: stats per question, add or edit one, retire or restore one diff --git a/test/gamepass.js b/test/gamepass.js index 5dd53ea..61ab6e6 100644 --- a/test/gamepass.js +++ b/test/gamepass.js @@ -56,19 +56,21 @@ const ok = (name, cond, info) => { if (cond) { pass++; console.log(' ok ', nam rewards.setSettings({ minPol: 0.05, maxPol: 1, dailyCapPol: 20, missionsPerDay: 3 }); const me = { memberId: 7, email: 'hugh@example.com', username: 'hugh', wallet: '0x' + 'a'.repeat(40) }, day = missions.ctDay(); const m1 = { id: 'm1', site: 'example.com' }, m2 = { id: 'm2', site: 'two.com' }, mpaid = { id: 'adv', site: 'adv.com', paid: true, hunterPol: 0.2 }; - const q1 = rewards.quote(m1); ok('the quote is the draw inside the range', q1 >= 0.05 && q1 <= 1); + const q1 = rewards.quote(m1, true); ok('the quote is the draw inside the range', q1 >= 0.05 && q1 <= 1); + const q0 = rewards.quote(m1, false); ok('the free tier draws on the small range (2026-11-02)', q0 >= 0.02 && q0 <= 0.1); let g = rewards.grant(me, m1, { pol: 0.03, nominal: q1, gp: { ref: 'find:m1:' + day, kind: 'daily' } }); ok('a find pays what IAP allowed, due for the faucet', g.ok && g.rec.pol === 0.03 && g.rec.status === 'due' && g.rec.nominal === q1 && g.rec.gp.ref === 'find:m1:' + day); g = rewards.grant(me, m2, { pol: 0, nominal: 0.2, gp: { ref: 'find:m2:' + day, kind: 'daily', capHit: 'daily' } }); ok('a find at the cap: recorded as capped, pays nothing, never reaches the faucet', g.capped && g.rec.status === 'capped' && g.rec.pol === 0 && !rewards.payable().some(p => p.id === g.rec.id)); - ok('a capped find still counts as today\'s find and completes the mission', rewards.findsToday(7) === 2 && rewards.completed(7, 'm2', me.wallet) && rewards.daily(7, new Set(), 0, 0).left === 1); + ok('a capped find still counts as today\'s find and completes the mission', rewards.findsToday(7) === 2 && rewards.completed(7, 'm2', me.wallet) && rewards.daily(7, new Set(), 0, 0, true).left === 1); const gw = rewards.grant(me, { id: 'm3', site: 'three.com' }, { pol: 0.4, status: 'gp-wait', nominal: 0.4, gp: { ref: 'find:m3:' + day, kind: 'daily', pending: true } }); ok('IAP unreachable: the find is recorded as gp-wait, not payable yet', gw.waiting && gw.rec.status === 'gp-wait' && !rewards.payable().some(p => p.id === gw.rec.id)); rewards.settleQueued(gw.rec.id, 0.25, { pass: false }); const settled = store.read('payouts', []).find(p => p.id === gw.rec.id); ok('the queue answer settles it: pays the allowed part, due', settled.pol === 0.25 && settled.status === 'due' && settled.gp.pending === false); rewards.settleQueued(gw.rec.id, 0.9, {}); ok('a settled row is not settled twice', store.read('payouts', []).find(p => p.id === gw.rec.id).pol === 0.25); const gpaid = rewards.grant(me, mpaid); ok('an advertiser-funded mission pays the advertiser\'s amount, ungated (no gp on the row)', gpaid.rec.pol === 0.2 && !gpaid.rec.gp && gpaid.rec.paid === true); - ok('the perk: +2 missions a day with the pass', rewards.daily(7, new Set(), 0, 2).limit === 5 && rewards.daily(7, new Set(), 0, 0).limit === 3); + ok('the perk: +2 missions a day with the pass', rewards.daily(7, new Set(), 0, 2, true).limit === 5 && rewards.daily(7, new Set(), 0, 0, true).limit === 3); + ok('the free tier: one hunt a day without the pass (2026-11-02)', rewards.daily(7, new Set(), 0, 0, false).limit === 1 && rewards.daily(7, new Set(), 0, 0).limit === 1); // ---- Ad Detective: the case is scored first, then IAP decides; a second case a day with the pass rewards.setSettings({ detectiveOn: 1, detectivePol: 0.15 });