Daily snapshot gains a Games block: members handed into each game (counted at hand-off, per hour) and payouts read from each game wallet on Polygon in the last 24 h, launches of the day called out

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-08 09:13:44 -05:00
parent d07a32a837
commit af5a53b833
3 changed files with 275 additions and 203 deletions
+58
View File
@@ -0,0 +1,58 @@
// Game figures for the daily snapshot (Marty 2026-10-08: one card for the whole ecosystem, games as their own block).
// Two live sources, no estimates:
// players sent in — counted here every time InstantAdPay hands a member into a game (/api/my/<game>), per UTC hour,
// so "last 24 h" is exact and survives restarts (DATA_DIR/game-handoffs.json)
// payouts + POL — read from Polygon: outgoing transfers from each game's payout wallet in the last 24 h (Etherscan v2,
// the same query the hourly wallet watcher on core uses). Our own wallets and the fee wallets are skipped.
// Env: GAME_WALLETS = "slug:0x…,slug:0x…" (set from the /root/.<game>-address files on core), ETHERSCAN_KEY.
'use strict';
const fs = require('fs');
const path = require('path');
let R = null;
const NAMES = { spookydoors: 'Spooky Doors', gemkingdom: 'Gem Kingdom', clutterhunt: 'ClutterHunt', driprunner: 'Drip Runner', polywarriors: 'PolyWarriors', spellwheel: 'SpellWheel', roadagent: 'Road Agent', polhunter: 'PolHunter', passivedrip: 'PassiveDrip' };
const wallets = () => Object.fromEntries(String(process.env.GAME_WALLETS || '').split(',').map(x => x.trim()).filter(Boolean).map(x => { const [k, a] = x.split(':'); return [String(k).toLowerCase(), String(a || '').toLowerCase()]; }).filter(([k, a]) => k && /^0x[0-9a-f]{40}$/.test(a)));
const KEY = () => String(process.env.ETHERSCAN_KEY || '').trim();
// money never flows to these from a game wallet as a payout: Marty's fee wallets, the other game wallets
const SKIP = () => new Set(['0x7627fc78876948ac9d95c1c9eb061e7d6d647b70', '0x8b7d33849a2c4d92c985be31e46dc564ba901ad2', '0xcbe203312e0ea3b542da7a2e7f0a8a09db948f75'].concat(Object.values(wallets())));
const FILE = () => path.join(R.dataDir, 'game-handoffs.json');
function load() { try { return JSON.parse(fs.readFileSync(FILE(), 'utf8')); } catch (e) { return {}; } }
function init(deps) { R = deps; }
const hourKey = t => new Date(t || Date.now()).toISOString().slice(0, 13);
// a member was handed into a game: one tick in this hour's bucket (buckets older than 3 days are dropped)
function handoff(slug) {
try {
const h = load(), k = hourKey(); h[k] = h[k] || {}; h[k][slug] = (h[k][slug] || 0) + 1;
const cut = hourKey(Date.now() - 3 * 86400000); for (const key of Object.keys(h)) if (key < cut) delete h[key];
fs.writeFileSync(FILE(), JSON.stringify(h));
} catch (e) { /* counting must never break a hand-off */ }
}
function sentIn(since) { const h = load(), out = {}; const k0 = hourKey(since); for (const [k, m] of Object.entries(h)) if (k >= k0) for (const [slug, c] of Object.entries(m)) out[slug] = (out[slug] || 0) + c; return out; }
// outgoing payouts from one game wallet since `since` (ms): { count, wei }
async function payoutsFor(addr, since) {
const out = { count: 0, wei: 0n }; if (!KEY()) return out;
const url = 'https://api.etherscan.io/v2/api?chainid=137&module=account&action=txlist&address=' + addr + '&startblock=0&endblock=99999999&sort=desc&page=1&offset=500&apikey=' + KEY();
const r = await fetch(url, { signal: AbortSignal.timeout(20000) }); const j = await r.json(); const rows = Array.isArray(j.result) ? j.result : [];
const skip = SKIP(), sinceS = Math.floor(since / 1000);
for (const x of rows) {
if (Number(x.timeStamp) < sinceS) break; // sorted newest first
if (x.isError !== '0' || String(x.from).toLowerCase() !== addr || !x.value || x.value === '0') continue;
if (skip.has(String(x.to).toLowerCase())) continue;
out.count++; out.wei += BigInt(x.value);
}
return out;
}
// everything the card needs: per game and totals, last 24 h
async function gather(since) {
const W = wallets(), sent = sentIn(since), games = [];
const slugs = new Set([...Object.keys(W), ...Object.keys(sent)]);
for (const slug of slugs) {
const g = { slug, name: NAMES[slug] || slug, sentIn: sent[slug] || 0, payouts: 0, wei: 0n, error: null };
if (W[slug]) { try { const p = await payoutsFor(W[slug], since); g.payouts = p.count; g.wei = p.wei; } catch (e) { g.error = e.message; } }
games.push(g);
}
games.sort((a, b) => (b.sentIn - a.sentIn) || (Number(b.wei - a.wei)));
const totals = games.reduce((t, g) => ({ sentIn: t.sentIn + g.sentIn, payouts: t.payouts + g.payouts, wei: t.wei + g.wei }), { sentIn: 0, payouts: 0, wei: 0n });
return { games, totals, chainChecked: !!KEY() && Object.keys(W).length > 0 };
}
module.exports = { init, handoff, gather, NAMES };
+11 -9
View File
@@ -40,6 +40,7 @@ const videosweep = require('./videosweep');
const sbcheck = require('./sbcheck'); const sbcheck = require('./sbcheck');
const reach = require('./reach'); const reach = require('./reach');
const lssync = require('./lssync'); const lssync = require('./lssync');
const gamestats = require('./gamestats');
const marks = require('./marks'); const marks = require('./marks');
const feedgroup = require('./feedgroup'); // one proof-feed message per purchase: buyer, package, then the tier payouts // one-time claims shared across running instances (deploy overlap) // Google Safe Browsing screen on advertiser destinations const feedgroup = require('./feedgroup'); // one proof-feed message per purchase: buyer, package, then the tier payouts // one-time claims shared across running instances (deploy overlap) // Google Safe Browsing screen on advertiser destinations
const updates = require('./updates'); const updates = require('./updates');
@@ -506,7 +507,8 @@ async function boot() {
coach.init({ dataDir: DATA_DIR, chain, accounts, mailer, ads, tank, lb: () => leaderboard, siteConfig }); coach.init({ dataDir: DATA_DIR, chain, accounts, mailer, ads, tank, lb: () => leaderboard, siteConfig });
pipeline.init({ dataDir: DATA_DIR, accounts, coach, chain }); pipeline.init({ dataDir: DATA_DIR, accounts, coach, chain });
badge.init({ publicDir: PUBLIC_DIR }); badge.init({ publicDir: PUBLIC_DIR });
snapshot.init({ dataDir: DATA_DIR, db, chain, siteConfig, publicDir: PUBLIC_DIR, gamestats.init({ dataDir: DATA_DIR });
snapshot.init({ dataDir: DATA_DIR, db, chain, siteConfig, publicDir: PUBLIC_DIR, games: gamestats, launchesToday: () => GAMES().filter(g => (g.soon && g.soon.opens === todayCT()) || (g.season && g.season.start === todayCT())).map(g => g.name),
send: async (c, t, th) => { await telegramSend(c, t, th); return true; }, send: async (c, t, th) => { await telegramSend(c, t, th); return true; },
sendPhoto: (c, jpeg, cap, th) => telegramSendPhoto(c, jpeg, cap, th) }); sendPhoto: (c, jpeg, cap, th) => telegramSendPhoto(c, jpeg, cap, th) });
fridaybank.init({ db }); fridaybank.init({ db });
@@ -2928,7 +2930,7 @@ const server = http.createServer(async (req, res) => {
return json(res, 200, await fridaybank.bankFor(email)); return json(res, 200, await fridaybank.bankFor(email));
} }
// -- PolHunter hand-off (2026-09-19): sign the member across; polhunter.com verifies with the shared secret // -- PolHunter hand-off (2026-09-19): sign the member across; polhunter.com verifies with the shared secret
if (p === '/api/my/polhunter' && req.method === 'GET') { if (p === '/api/my/polhunter' && req.method === 'GET') { gamestats.handoff('polhunter');
const s = await auth.fromRequest(req); const s = await auth.fromRequest(req);
// not signed in: to sign-in, keeping a PolHunter share link's ?ref so the newcomer's sponsor holds (the viral-link rule on /my sets it) // not signed in: to sign-in, keeping a PolHunter share link's ?ref so the newcomer's sponsor holds (the viral-link rule on /my sets it)
if (!s || !s.email) { const ref = String(u.searchParams.get('ref') || '').trim().toLowerCase().replace(/[^a-z0-9_]/g, '').slice(0, 20); res.writeHead(302, { Location: '/my' + (ref ? '?ref=' + ref : '') }); return res.end(); } if (!s || !s.email) { const ref = String(u.searchParams.get('ref') || '').trim().toLowerCase().replace(/[^a-z0-9_]/g, '').slice(0, 20); res.writeHead(302, { Location: '/my' + (ref ? '?ref=' + ref : '') }); return res.end(); }
@@ -2949,7 +2951,7 @@ const server = http.createServer(async (req, res) => {
res.writeHead(302, { Location: huntUrl + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': 'iap.return=; Path=/; SameSite=Lax; Max-Age=0' + (IS_PROD ? '; Secure' : '') }); return res.end(); // the loop is closed res.writeHead(302, { Location: huntUrl + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': 'iap.return=; Path=/; SameSite=Lax; Max-Age=0' + (IS_PROD ? '; Secure' : '') }); return res.end(); // the loop is closed
} }
// -- Drip Runner hand-off (2026-09-30): sign the member across, the game verifies with the shared secret // -- Drip Runner hand-off (2026-09-30): sign the member across, the game verifies with the shared secret
if (p === '/api/my/driprunner' && req.method === 'GET') { if (p === '/api/my/driprunner' && req.method === 'GET') { gamestats.handoff('driprunner');
const s = await auth.fromRequest(req); const s = await auth.fromRequest(req);
if (!s || !s.email) { res.writeHead(302, { Location: '/my' + refQ(u), 'Set-Cookie': 'iap.return=driprunner; Path=/; SameSite=Lax; Max-Age=1800' + (IS_PROD ? '; Secure' : ''), 'Cache-Control': 'no-store' }); return res.end(); } // sign in first, then straight back into the game if (!s || !s.email) { res.writeHead(302, { Location: '/my' + refQ(u), 'Set-Cookie': 'iap.return=driprunner; Path=/; SameSite=Lax; Max-Age=1800' + (IS_PROD ? '; Secure' : ''), 'Cache-Control': 'no-store' }); return res.end(); } // sign in first, then straight back into the game
if (DR_SECRET().length < 32) return json(res, 503, { error: 'Drip Runner is not connected yet.' }); if (DR_SECRET().length < 32) return json(res, 503, { error: 'Drip Runner is not connected yet.' });
@@ -2986,7 +2988,7 @@ const server = http.createServer(async (req, res) => {
console.log('polywarriors weekly prize', k, acct.email, credits); console.log('polywarriors weekly prize', k, acct.email, credits);
return json(res, 200, { ok: true, credits }); return json(res, 200, { ok: true, credits });
} }
if (p === '/api/my/polywarriors' && req.method === 'GET') { if (p === '/api/my/polywarriors' && req.method === 'GET') { gamestats.handoff('polywarriors');
const s = await auth.fromRequest(req); const s = await auth.fromRequest(req);
if (!s || !s.email) { res.writeHead(302, { Location: '/my' + refQ(u), 'Set-Cookie': gkCookie('iap.return', 'polywarriors', 1800), 'Cache-Control': 'no-store' }); return res.end(); } if (!s || !s.email) { res.writeHead(302, { Location: '/my' + refQ(u), 'Set-Cookie': gkCookie('iap.return', 'polywarriors', 1800), 'Cache-Control': 'no-store' }); return res.end(); }
if (PW_SECRET().length < 32) return json(res, 503, { error: 'PolyWarriors is not connected yet.' }); if (PW_SECRET().length < 32) return json(res, 503, { error: 'PolyWarriors is not connected yet.' });
@@ -2995,7 +2997,7 @@ const server = http.createServer(async (req, res) => {
res.writeHead(302, { Location: PW_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': gkCookie('iap.return', '', 0) }); return res.end(); res.writeHead(302, { Location: PW_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': gkCookie('iap.return', '', 0) }); return res.end();
} }
// -- SpellWheel hand-off (2026-10-04): sign the member across; the game verifies with SW_SSO_SECRET // -- SpellWheel hand-off (2026-10-04): sign the member across; the game verifies with SW_SSO_SECRET
if (p === '/api/my/spellwheel' && req.method === 'GET') { if (p === '/api/my/spellwheel' && req.method === 'GET') { gamestats.handoff('spellwheel');
const s = await auth.fromRequest(req); const s = await auth.fromRequest(req);
if (!s || !s.email) { res.writeHead(302, { Location: '/my' + refQ(u), 'Set-Cookie': gkCookie('iap.return', 'spellwheel', 1800), 'Cache-Control': 'no-store' }); return res.end(); } if (!s || !s.email) { res.writeHead(302, { Location: '/my' + refQ(u), 'Set-Cookie': gkCookie('iap.return', 'spellwheel', 1800), 'Cache-Control': 'no-store' }); return res.end(); }
if (SW_SECRET().length < 32) return json(res, 503, { error: 'SpellWheel is not connected yet.' }); if (SW_SECRET().length < 32) return json(res, 503, { error: 'SpellWheel is not connected yet.' });
@@ -3004,7 +3006,7 @@ const server = http.createServer(async (req, res) => {
res.writeHead(302, { Location: SW_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': gkCookie('iap.return', '', 0) }); return res.end(); res.writeHead(302, { Location: SW_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': gkCookie('iap.return', '', 0) }); return res.end();
} }
// -- ClutterHunt hand-off (2026-10-03): sign the member across; the game verifies with SEEK_SSO_SECRET // -- ClutterHunt hand-off (2026-10-03): sign the member across; the game verifies with SEEK_SSO_SECRET
if (p === '/api/my/clutterhunt' && req.method === 'GET') { if (p === '/api/my/clutterhunt' && req.method === 'GET') { gamestats.handoff('clutterhunt');
const s = await auth.fromRequest(req); const s = await auth.fromRequest(req);
if (!s || !s.email) { res.writeHead(302, { Location: '/my' + refQ(u), 'Set-Cookie': gkCookie('iap.return', 'clutterhunt', 1800), 'Cache-Control': 'no-store' }); return res.end(); } if (!s || !s.email) { res.writeHead(302, { Location: '/my' + refQ(u), 'Set-Cookie': gkCookie('iap.return', 'clutterhunt', 1800), 'Cache-Control': 'no-store' }); return res.end(); }
if (SEEK_SECRET().length < 32) return json(res, 503, { error: 'ClutterHunt is not connected yet.' }); if (SEEK_SECRET().length < 32) return json(res, 503, { error: 'ClutterHunt is not connected yet.' });
@@ -3013,7 +3015,7 @@ const server = http.createServer(async (req, res) => {
res.writeHead(302, { Location: SEEK_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': gkCookie('iap.return', '', 0) }); return res.end(); res.writeHead(302, { Location: SEEK_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': gkCookie('iap.return', '', 0) }); return res.end();
} }
// -- Gem Kingdom hand-off (2026-10-01): sign the member across; the game verifies with GK_SSO_SECRET // -- Gem Kingdom hand-off (2026-10-01): sign the member across; the game verifies with GK_SSO_SECRET
if (p === '/api/my/gemkingdom' && req.method === 'GET') { if (p === '/api/my/gemkingdom' && req.method === 'GET') { gamestats.handoff('gemkingdom');
const s = await auth.fromRequest(req); const s = await auth.fromRequest(req);
// a newcomer from a Gem Kingdom feed post carries the poster's ?ref through to /my, where the viral-link rule sets the sponsor // a newcomer from a Gem Kingdom feed post carries the poster's ?ref through to /my, where the viral-link rule sets the sponsor
const gkRef = String(u.searchParams.get('ref') || '').trim().toLowerCase().replace(/[^a-z0-9_]/g, '').slice(0, 20); const gkRef = String(u.searchParams.get('ref') || '').trim().toLowerCase().replace(/[^a-z0-9_]/g, '').slice(0, 20);
@@ -3129,7 +3131,7 @@ const server = http.createServer(async (req, res) => {
if (ss === 'hidden') return json(res, 200, { show: false }); if (ss === 'hidden') return json(res, 200, { show: false });
return json(res, 200, { show: true, preview: ss === 'preview', base: SD_URL(), image: SD_URL() + '/og-spookydoors.jpg', season: { start: SD_SEASON.start, end: SD_SEASON.end } }); return json(res, 200, { show: true, preview: ss === 'preview', base: SD_URL(), image: SD_URL() + '/og-spookydoors.jpg', season: { start: SD_SEASON.start, end: SD_SEASON.end } });
} }
if (p === '/api/my/spookydoors' && req.method === 'GET') { if (p === '/api/my/spookydoors' && req.method === 'GET') { gamestats.handoff('spookydoors');
const s = await auth.fromRequest(req); const s = await auth.fromRequest(req);
// a newcomer from a Spooky Doors post carries the poster's ?ref through to /my, where the viral-link rule sets the sponsor // a newcomer from a Spooky Doors post carries the poster's ?ref through to /my, where the viral-link rule sets the sponsor
const sdRef = String(u.searchParams.get('ref') || '').trim().toLowerCase().replace(/[^a-z0-9_]/g, '').slice(0, 20); const sdRef = String(u.searchParams.get('ref') || '').trim().toLowerCase().replace(/[^a-z0-9_]/g, '').slice(0, 20);
@@ -3141,7 +3143,7 @@ const server = http.createServer(async (req, res) => {
res.writeHead(302, { Location: SD_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': gkCookie('iap.return', '', 0) }); return res.end(); res.writeHead(302, { Location: SD_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': gkCookie('iap.return', '', 0) }); return res.end();
} }
// -- Road Agent hand-off (2026-10-07): sign the member across; the game verifies with RA_SSO_SECRET // -- Road Agent hand-off (2026-10-07): sign the member across; the game verifies with RA_SSO_SECRET
if (p === '/api/my/roadagent' && req.method === 'GET') { if (p === '/api/my/roadagent' && req.method === 'GET') { gamestats.handoff('roadagent');
const s = await auth.fromRequest(req); const s = await auth.fromRequest(req);
const raRef = String(u.searchParams.get('ref') || '').trim().toLowerCase().replace(/[^a-z0-9_]/g, '').slice(0, 20); const raRef = String(u.searchParams.get('ref') || '').trim().toLowerCase().replace(/[^a-z0-9_]/g, '').slice(0, 20);
if (!s || !s.email) { res.writeHead(302, { Location: '/my' + (raRef ? '?ref=' + encodeURIComponent(raRef) : ''), 'Set-Cookie': gkCookie('iap.return', 'roadagent', 1800), 'Cache-Control': 'no-store' }); return res.end(); } if (!s || !s.email) { res.writeHead(302, { Location: '/my' + (raRef ? '?ref=' + encodeURIComponent(raRef) : ''), 'Set-Cookie': gkCookie('iap.return', 'roadagent', 1800), 'Cache-Control': 'no-store' }); return res.end(); }
+12
View File
@@ -50,6 +50,9 @@ async function gather(now = Date.now()) {
const t = X.chain.totals ? X.chain.totals() : null; const t = X.chain.totals ? X.chain.totals() : null;
if (t) { if (t.purchases) s.lifeBuys = Number(t.purchases); if (t.payoutWei) s.lifePaidWei = BigInt(t.payoutWei); if (t.payouts) s.lifePayouts = Number(t.payouts); } if (t) { if (t.purchases) s.lifeBuys = Number(t.purchases); if (t.payoutWei) s.lifePaidWei = BigInt(t.payoutWei); if (t.payouts) s.lifePayouts = Number(t.payouts); }
} catch (e) {} } catch (e) {}
// the games (2026-10-08): members sent in (counted at hand-off) + payouts read from each game wallet on Polygon
try { s.games = X.games ? await X.games.gather(since) : null; } catch (e) { s.games = null; }
try { s.launches = X.launchesToday ? X.launchesToday() : []; } catch (e) { s.launches = []; }
return s; return s;
} }
@@ -77,6 +80,15 @@ function compose(s, cta) {
B.push('\u{1F4B3} <b>Credits</b>\n' B.push('\u{1F4B3} <b>Credits</b>\n'
+ '<b>' + n(s.creditsHandedOut) + '</b> handed out · <b>' + n(s.creditsEarned) + '</b> earned\n' + '<b>' + n(s.creditsHandedOut) + '</b> handed out · <b>' + n(s.creditsEarned) + '</b> earned\n'
+ n(s.creditsSpent) + ' spent on ads'); + n(s.creditsSpent) + ' spent on ads');
if (s.games && (s.games.totals.sentIn || s.games.totals.payouts || (s.launches && s.launches.length))) {
const G = s.games, live = G.games.filter(g => g.sentIn || g.payouts);
let gl = '\u{1F3AE} <b>Games</b>\n';
if (s.launches && s.launches.length) gl += '\u{1F680} ' + s.launches.join(' and ') + ' opened today\n';
gl += '<b>' + n(G.totals.sentIn) + '</b> members played' + (G.chainChecked ? ' \u00b7 <b>' + pol(G.totals.wei) + ' POL</b> paid in ' + plural(G.totals.payouts, 'payout') : '') + '\n';
gl += live.slice(0, 6).map(g => g.name + ': ' + n(g.sentIn) + (g.payouts ? ' \u00b7 ' + pol(g.wei) + ' POL' : '')).join('\n');
if (live.length) gl += '\nBusiest: ' + live[0].name;
B.push(gl.trim());
}
B.push('\u{1F3C1} <b>So far</b>\n' B.push('\u{1F3C1} <b>So far</b>\n'
+ '<b>' + n(s.members) + '</b> members · ' + n(s.wallets) + ' wallets linked\n' + '<b>' + n(s.members) + '</b> members · ' + n(s.wallets) + ' wallets linked\n'
+ n(s.payoutsOn) + ' with payouts on · ' + n(s.lifeBuys) + ' buys\n' + n(s.payoutsOn) + ' with payouts on · ' + n(s.lifeBuys) + ' buys\n'