Launch week: Founder badge + launch week contest (Marty approved 2026-11-05, PLAN.md options B and C)
Founder badge (cosmetic only: no credits, no POL, no perks, never posted to Telegram) - Criterion: the account's earliest signed-in visit is before the launch moment (launchAt, default 2026-11-15T06:00:00-06:00). Field: accounts.firstSeen, else lastSeen. Both are written only by accounts.touchSeen() on signed-in requests (dashboard, ping, chat); touchSeen now keeps firstSeen = the previous lastSeen on the next visit, so a pre-launch member who signs in again after launch still qualifies. Carried-over shells that never signed in have neither field and never qualify. - Stored flag accounts.founder (JSON + MySQL column). Grant: launchweek.tick every 10 minutes from the launch moment, idempotent, one run per 10-minute slot across app copies (marks.claim); founderGrant '0' turns it off. Admin preview + "Grant Founder badges now" (refused before launch). - Shown in the badge strip (on the way before launch, Share works, no Telegram post), wall (wall-founder.js), Team rows (my.js + team.js), the Team activity chip, and next to names on /leaderboard. Art: /badges/badge-founder.jpg, drawn in code in the existing card layout. Launch week contest - Window [launchContestStart or launchAt, launchContestEnd) = Sun Nov 15 6:00 AM to the end of Sat Nov 21, Central (end stored exclusive, 2026-11-22T00:00:00-06:00). Count = the weekly board's tier-1 TierPaid sales. Never counted: own positions, buys by linked positions (Qualified Start), the admin account and overrideHouseIds (as contestants or buyers), launchContestExcludeEmails/Ids. launchContestMinSales 2. Ties: sales, dollars, who got there first. Prizes launchContestPrizesPol '10,6,4'. - Payout only by Admin > Launch week > Pay launch contest: the ranking is frozen on the first press, the admin's confirmed list must match it, balance + gas checked first, each place claimed once (marks.claim) and written as sending before award(memberId) from the Level 4 override payer wallet (override.payerHandle). Records tx hashes; resolve paid-with-tx or retry for blocked/failed/review. The prize email + feed line say "Launch week contest prize". - /leaderboard panel from the launch moment until the prizes are paid; /launch copy states both rules. - chatbot: CANNED founder-badge + launch-contest, FACTS lines (no amounts quoted before launch). - qa/launchweek.test.cjs (16 checks: Central window bounds, exclusions, minimum, two-copy payout once, frozen result, Founder criterion + grant, touchSeen backfill); run.sh launchweek and in all. - Versions: my.js?v=20261105fd, team.js?v=20261105fd, wall-founder.js?v=20261105fd, admin-launchweek.js?v=20261105lw (wall.js unchanged: the shared policy test pins it). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -90,6 +90,7 @@ const TRAFFIC_PAGES = new Set(['/', '/ledger', '/contract', '/shorts', '/plays',
|
||||
let tankWaitCache = null; // dashboard: who is waiting for a sponsor (refreshed every minute)
|
||||
const geo = require('./geo'); // viewer country -> tier (DB-IP lite), for campaign targeting
|
||||
const burner = require('./burner'); // automatic on-chain credit burns (inert without ENGINE_KEY)
|
||||
const launchweek = require('./launchweek'); // launch week (2026-11-05): Founder badge grant + the launch contest (admin-approved POL prizes)
|
||||
const override = require('./override'); // level-4 override: weekly dry-run report; the payer ships OFF (overrideMode 'live' + overrideGoLive + OVERRIDE_PAYER_KEY), 2026-10-23
|
||||
|
||||
const PORT = Number(process.env.PORT || 3000);
|
||||
@@ -769,6 +770,11 @@ async function boot() {
|
||||
override.init({ dataDir: DATA_DIR, chain, siteConfig, db, brand: 'LinkSpin', siteUrl: SITE_URL,
|
||||
notify: async text => { const sc = siteConfig(); if (sc.telegramBotToken && sc.telegramAdminChatId) { await telegramSend(sc.telegramAdminChatId, text); return true; } if (ADMIN_EMAIL && mailer.hasKey()) { await mailer.send(ADMIN_EMAIL, 'LinkSpin: level-4 override', text.replace(/<[^>]+>/g, '')); return true; } return false; } });
|
||||
setInterval(() => override.tick().catch(e => console.error('override', e.message)), 30 * 60 * 1000);
|
||||
// launch week: Founder grant from the launch moment (idempotent, every 10 minutes) + the /leaderboard contest panel; POL prizes only by the admin button
|
||||
launchweek.init({ accounts, chain, marks, leaderboard, siteConfig, dataDir: DATA_DIR, adminEmail: ADMIN_EMAIL, payer: () => override.payerHandle(), txLink: h => override.polygonTx(h) });
|
||||
leaderboard.setLaunchPanel(() => launchweek.panelHtml());
|
||||
setTimeout(() => launchweek.tick().catch(e => console.error('launchweek', e.message)), 2 * 60 * 1000);
|
||||
setInterval(() => launchweek.tick().catch(e => console.error('launchweek', e.message)), 10 * 60 * 1000);
|
||||
if (OUTBOUND_MAIL) { // same for the lead follow-up sequence
|
||||
setTimeout(() => drip.tick().catch(e => console.error('drip', e.message)), 30 * 1000);
|
||||
setInterval(() => drip.tick().catch(e => console.error('drip', e.message)), 10 * 60 * 1000);
|
||||
@@ -802,6 +808,8 @@ function siteConfig() {
|
||||
telegramEchoChatId: '', telegramEchoTopicId: '', telegramEchoEvents: 'payouts', // shared cross-program payments topic
|
||||
telegramAdminChatId: '', // private chat for admin alerts (sign-up guard bursts); falls back to ADMIN_EMAIL
|
||||
spamScanAllow: spamscan.DEFAULT_ALLOW.join(', '), // link-farm scan (2026-10-30): emails never listed as candidates; Admin > Members > Link-farm list > Allow adds here
|
||||
founderGrant: '1', // Founder badge: '0' stops the automatic grant at the launch moment (launchweek.js); the badge is cosmetic
|
||||
launchContest: '1', launchContestStart: '', launchContestEnd: '2026-11-22T00:00:00-06:00', launchContestPrizesPol: '10,6,4', launchContestMinSales: 2, launchContestMinCents: 0, launchContestExcludeEmails: '', launchContestExcludeIds: '', // launch week contest: start '' = launchAt; end is EXCLUSIVE (all of Sat Nov 21 Central); POL prizes 1st,2nd,3rd paid only by the admin button; admin + overrideHouseIds always excluded
|
||||
launchAt: '', // public launch moment, ISO 8601 with offset (e.g. 2026-09-18T19:00:00-05:00): countdown on /launch + dashboard mark
|
||||
aiCreditsPerGen: 10, aiFreeSurge: 20, aiFreeCircuit: 60, aiFreeNexus: 150, // AI Copy Engine: free generations per month by badge, then credits per generation
|
||||
carryClaimDays: '3',
|
||||
@@ -1099,7 +1107,9 @@ async function emailOnEvent(ev) {
|
||||
}
|
||||
else if (ev.type === 'AwardPaid') {
|
||||
const ov = override.txInfo(ev.tx); // a level-4 override payment from the weekly payer
|
||||
if (ov) await tell(ev.toId, 'Your Level 4 override is paid: ' + weiToPol(ev.amountWei) + ' POL', 'Your Level 4 override for the week of ' + ov.week + ' just landed in your wallet: ' + weiToPol(ev.amountWei) + ' POL. That is 3 percent of the purchases made four levels down in your line (or deeper, when the upline between was not yet qualified), paid weekly from the company wallet. You earn it while you have 5 or more qualifying buyers.\n\nTransaction: ' + txUrlOf(ev.tx) + '\n\nYour wallet and payouts: ' + SITE_URL + '/wallet');
|
||||
const lw = !ov && launchweek.txInfo(ev.tx); // a launch week contest prize (admin-approved)
|
||||
if (lw) await tell(ev.toId, 'Your launch week contest prize is paid: ' + weiToPol(ev.amountWei) + ' POL', 'You placed ' + ['1st', '2nd', '3rd', '4th', '5th'][lw.place - 1] + ' in the LinkSpin launch week contest. Your prize just landed in your wallet: ' + weiToPol(ev.amountWei) + ' POL.\n\nTransaction: ' + txUrlOf(ev.tx) + '\n\nYour wallet and payouts: ' + SITE_URL + '/wallet');
|
||||
else if (ov) await tell(ev.toId, 'Your Level 4 override is paid: ' + weiToPol(ev.amountWei) + ' POL', 'Your Level 4 override for the week of ' + ov.week + ' just landed in your wallet: ' + weiToPol(ev.amountWei) + ' POL. That is 3 percent of the purchases made four levels down in your line (or deeper, when the upline between was not yet qualified), paid weekly from the company wallet. You earn it while you have 5 or more qualifying buyers.\n\nTransaction: ' + txUrlOf(ev.tx) + '\n\nYour wallet and payouts: ' + SITE_URL + '/wallet');
|
||||
else await tell(ev.toId, 'You just got paid ' + weiToPol(ev.amountWei) + ' POL on LinkSpin', weiToPol(ev.amountWei) + ' POL just landed in your wallet.\n\nTransaction: ' + txUrlOf(ev.tx) + '\n\nYour wallet and payouts: ' + SITE_URL + '/wallet');
|
||||
}
|
||||
else if (ev.type === 'PassedUp' && ev.reason === 'send-failed') {
|
||||
@@ -1143,7 +1153,7 @@ async function telegramOnEvent(ev) {
|
||||
if (ev.type === 'TierPaid') line = '\u{1F4B8} Level ' + ev.tier + ' payout: <b>' + weiToPol(ev.amountWei) + ' POL</b> \u2192 ' + who(ev.recipientId);
|
||||
else if (ev.type === 'BuyerCounted' && mode !== 'payouts') line = '\u2B50 ' + who(ev.sponsorId) + ' now has <b>' + ev.newCount + '</b> qualifying buyer' + (ev.newCount === 1 ? '' : 's') + (ev.newCount === 2 ? ' \u00b7 level 2 open' : ev.newCount === 5 ? ' \u00b7 level 3 open' : '');
|
||||
else if (ev.type === 'Purchase' && mode !== 'payouts') line = '\u{1F9FE} ' + who(ev.buyerId) + ' bought a $' + Math.round(ev.priceCents / 100) + ' package';
|
||||
else if (ev.type === 'AwardPaid') line = '\u{1F4B8} ' + (override.txInfo(ev.tx) ? 'Level 4 override' : 'Award payout') + ': <b>' + weiToPol(ev.amountWei) + ' POL</b> \u2192 ' + who(ev.toId);
|
||||
else if (ev.type === 'AwardPaid') line = '\u{1F4B8} ' + (override.txInfo(ev.tx) ? 'Level 4 override' : launchweek.txInfo(ev.tx) ? 'Launch week contest prize' : 'Award payout') + ': <b>' + weiToPol(ev.amountWei) + ' POL</b> \u2192 ' + who(ev.toId);
|
||||
else if (ev.type === 'MemberActivated' && mode === 'all') line = '\u{1F91D} ' + who(ev.id) + ' switched on payouts';
|
||||
if (!line) return null;
|
||||
return line + ' \u00b7 <a href="' + tx + '">verify</a>' + (sc.telegramCtaUrl ? '\n<a href="' + sc.telegramCtaUrl + '">Join free</a>' : '');
|
||||
@@ -1290,8 +1300,10 @@ async function telegramSendPhoto(chatId, jpeg, caption, threadId) {
|
||||
rq.on('error', () => resolve(false)); rq.on('timeout', () => { rq.destroy(); resolve(false); }); rq.end(body);
|
||||
});
|
||||
}
|
||||
const BADGE_META = { payouts: ['Spark', 'payouts switched on'], firstBuyer: ['Surge', 'first qualifying buyer'], level2: ['Circuit', 'two qualifying buyers, level 2 open'], level3: ['Nexus', 'five qualifying buyers, fully qualified'] };
|
||||
const BADGE_META = { founder: ['Founder', 'signed in before LinkSpin launched'], payouts: ['Spark', 'payouts switched on'], firstBuyer: ['Surge', 'first qualifying buyer'], level2: ['Circuit', 'two qualifying buyers, level 2 open'], level3: ['Nexus', 'five qualifying buyers, fully qualified'] };
|
||||
const BADGE_LOG = () => path.join(DATA_DIR, 'badge-posts.json');
|
||||
// every badge a member holds: the chain milestones plus the stored Founder flag (2026-11-05)
|
||||
async function badgesHeld(email) { const out = []; try { out.push(...await ads.milestonesOf(email)); } catch (e) {} try { const a = await accounts.byEmail(email); if (a && a.founder) out.push('founder'); } catch (e) {} return out; }
|
||||
function badgeLog() { try { return JSON.parse(fs.readFileSync(BADGE_LOG(), 'utf8')); } catch (e) { return {}; } }
|
||||
|
||||
// ---- live feed (SSE) ----
|
||||
@@ -2127,6 +2139,7 @@ const server = http.createServer(async (req, res) => {
|
||||
if (bc >= 5) reached.push('level3');
|
||||
try { for (const k of await ads.milestonesOf(out.email)) if (!reached.includes(k)) reached.push(k); } catch (e) {} // a badge once earned stays earned
|
||||
out.milestonesReached = reached;
|
||||
try { const fs0 = launchweek.founderState(acct || await accounts.byEmail(out.email)); out.founder = fs0.founder; out.founderPending = fs0.pending; } catch (e) {} // Founder badge: cosmetic, never in milestonesReached (no credits)
|
||||
if (out.email && reached.length) out.milestonesGranted = await ads.grantMilestones(out.email, reached);
|
||||
}
|
||||
// who joined through this member: their invite link uses username when set,
|
||||
@@ -2348,6 +2361,9 @@ const server = http.createServer(async (req, res) => {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
return json(res, 200, await toolkit.adminUsage());
|
||||
}
|
||||
if (p === '/api/launch-week' && req.method === 'GET') { // public: launch moment + whether the contest panel is live (for /launch)
|
||||
return json(res, 200, await launchweek.publicView());
|
||||
}
|
||||
if (p === '/api/leaderboard' && req.method === 'GET') { // public standings; signed-in members also get their own row
|
||||
const s = await auth.fromRequest(req);
|
||||
const period = ['week', 'month', 'all', 'lastweek', 'lastmonth'].includes(u.searchParams.get('period')) ? u.searchParams.get('period') : 'week';
|
||||
@@ -2462,6 +2478,7 @@ const server = http.createServer(async (req, res) => {
|
||||
if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
|
||||
const key = String(u.searchParams.get('key') || '');
|
||||
if (!BADGE_META[key]) return json(res, 400, { error: 'Unknown badge.' });
|
||||
if (key === 'founder') return json(res, 400, { error: 'The Founder badge is not posted to Telegram.' }); // launch week: no mass badge posts (Marty 2026-11-05)
|
||||
if (!/^image\/jpeg/.test(String(req.headers['content-type'] || ''))) return json(res, 400, { error: 'Send the badge as a JPEG.' });
|
||||
let jpeg; try { jpeg = await readRaw(req, 1.5 * 1024 * 1024); } catch (e) { return json(res, 413, { error: 'Image too large.' }); }
|
||||
if (!jpeg || jpeg.length < 2000 || jpeg[0] !== 0xff || jpeg[1] !== 0xd8) return json(res, 400, { error: 'That is not a JPEG.' });
|
||||
@@ -2494,7 +2511,7 @@ const server = http.createServer(async (req, res) => {
|
||||
if (!BADGE_META[key]) return json(res, 400, { error: 'Unknown badge.' });
|
||||
let jpeg; try { jpeg = await readRaw(req, 1.5 * 1024 * 1024); } catch (e) { return json(res, 413, { error: 'Image too large.' }); }
|
||||
if (!jpeg || jpeg.length < 2000 || jpeg[0] !== 0xff || jpeg[1] !== 0xd8) return json(res, 400, { error: 'That is not a JPEG.' });
|
||||
if (!(await ads.milestonesOf(s.email)).includes(key)) return json(res, 400, { error: 'You have not unlocked that badge yet.' });
|
||||
if (!(await badgesHeld(s.email)).includes(key)) return json(res, 400, { error: 'You have not unlocked that badge yet.' });
|
||||
const a = await accounts.byEmail(s.email);
|
||||
if (!a || !a.username) return json(res, 400, { error: 'Pick a username first; the share page carries it.' });
|
||||
fs.writeFileSync(path.join(UPLOADS_DIR, 'badge-' + a.username + '-' + key + '.jpg'), jpeg);
|
||||
@@ -3177,6 +3194,7 @@ const server = http.createServer(async (req, res) => {
|
||||
memberId: m.memberId || 0,
|
||||
sponsor: sponsorOf(m),
|
||||
name: m.username ? '@' + m.username : m.memberId ? 'member #' + m.memberId : 'member',
|
||||
founder: !!m.founder, // Founder badge (cosmetic)
|
||||
ref: m.code || null, // opens the activity drop-down (Clinton's ask, 2026-09-14): any of the three levels
|
||||
email: L.level === 1 ? m.email : null, // directs only
|
||||
joined: m.created,
|
||||
@@ -3205,7 +3223,7 @@ const server = http.createServer(async (req, res) => {
|
||||
try { const cs = await ads.listCampaigns(a.email); out.campaigns = cs.length; out.campaignsActive = cs.filter(c => c.status === 'active').length; out.imps = cs.reduce((n, c) => n + (c.imps || 0) + (c.impsNas || 0), 0); } catch (e) {}
|
||||
try { const ls = await coach.linkStats(a.email); out.linkViews30 = (ls.angles || []).reduce((n, r) => n + (r.views30 || 0), 0); out.linkViews = ls.totalViews || 0; out.joins = ls.totalJoins || 0; } catch (e) {}
|
||||
try { out.directs = ((await accounts.downline(a.email, 1))[0] || { members: [] }).members.length; } catch (e) { out.directs = 0; }
|
||||
try { out.badges = await ads.milestonesOf(a.email); } catch (e) { out.badges = []; }
|
||||
out.badges = await badgesHeld(a.email); // chain milestones + Founder
|
||||
try { out.positions = (await accounts.positions(a.email)).length; } catch (e) { out.positions = 0; }
|
||||
return json(res, 200, out);
|
||||
}
|
||||
@@ -3563,6 +3581,7 @@ const server = http.createServer(async (req, res) => {
|
||||
let socials = null; if (bought) { try { socials = a.socials ? JSON.parse(a.socials) : null; } catch (e) {} }
|
||||
return json(res, 200, { name: a.username ? '@' + a.username : 'member #' + (a.memberId || 0), bought,
|
||||
avatarUrl: bought ? (a.avatarUrl || null) : null, bio: bought ? (a.bio || null) : null, socials, badge,
|
||||
founder: a.founder ? { img: '/badges/badge-founder.jpg', label: 'Founder' } : null, // cosmetic Founder badge (2026-11-05)
|
||||
joinUrl: joinPath, qrUrl: '/api/qr?d=' + encodeURIComponent(SITE_URL + joinPath), ladder: finalLadder, unlocked, buyerCount: bc });
|
||||
}
|
||||
// -- watch-to-earn video ads: serve one, then reward a server-clock-verified watch
|
||||
@@ -4027,6 +4046,25 @@ const server = http.createServer(async (req, res) => {
|
||||
const r = await override.resolve(String(b.week || ''), Number(b.memberId), String(b.action || ''), String(b.tx || ''));
|
||||
return json(res, r && r.error ? 400 : 200, r);
|
||||
}
|
||||
// -- launch week (2026-11-05): Founder badge preview/grant + launch contest standings and the admin-approved POL payout
|
||||
if (p === '/api/admin/launch-week' && req.method === 'GET') {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
return json(res, 200, await launchweek.adminView(), { 'Cache-Control': 'no-store' });
|
||||
}
|
||||
if (p === '/api/admin/launch-week/founders' && req.method === 'POST') { // run the Founder grant now (refused before the launch moment)
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
const r = await launchweek.grantFounders({ manual: true }); return json(res, r.error ? 400 : 200, Object.assign(r, { preview: await launchweek.founderPreview() }));
|
||||
}
|
||||
if (p === '/api/admin/launch-week/pay' && req.method === 'POST') { // pays the frozen places that match the list the admin confirmed; never twice
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
const b = await readBody(req); if (!b || b.confirm !== true) return json(res, 400, { error: 'Send confirm: true with the places you saw.' });
|
||||
const r = await launchweek.pay(b.places); return json(res, r.error ? 400 : 200, r);
|
||||
}
|
||||
if (p === '/api/admin/launch-week/resolve' && req.method === 'POST') {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
const b = await readBody(req); const r = await launchweek.resolve(Number(b.place), String(b.action || ''), String(b.tx || ''));
|
||||
return json(res, r.error ? 400 : 200, r);
|
||||
}
|
||||
if (p === '/api/admin/site' && req.method === 'GET') {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
return json(res, 200, { site: siteConfig() });
|
||||
@@ -4219,14 +4257,14 @@ const server = http.createServer(async (req, res) => {
|
||||
if (p === '/partners') return sendFile(res, path.join(PUBLIC_DIR, 'partners.html')); // site-owner kit (Marty, 2026-09-12)
|
||||
if (p === '/earning') return sendFile(res, path.join(PUBLIC_DIR, 'earning.html')); // member guide: how earning works (2026-09-12)
|
||||
// -- badge share page + image: /b/<username>/<key> (OG preview = the member's composed badge) (Marty, 2026-09-13)
|
||||
m = /^\/badge-img\/([a-z0-9_]{3,20})\/(payouts|firstBuyer|level2|level3)\.jpg$/.exec(p);
|
||||
m = /^\/badge-img\/([a-z0-9_]{3,20})\/(payouts|firstBuyer|level2|level3|founder)\.jpg$/.exec(p);
|
||||
if (m) return sendFile(res, path.join(UPLOADS_DIR, 'badge-' + m[1] + '-' + m[2] + '.jpg'));
|
||||
m = /^\/b\/([a-z0-9_]{3,20})\/(payouts|firstBuyer|level2|level3)$/i.exec(p);
|
||||
m = /^\/b\/([a-z0-9_]{3,20})\/(payouts|firstBuyer|level2|level3|founder)$/i.exec(p);
|
||||
if (m) {
|
||||
const un = m[1].toLowerCase(), key = m[2];
|
||||
const a = await accounts.byUsername(un);
|
||||
const file = path.join(UPLOADS_DIR, 'badge-' + un + '-' + key + '.jpg');
|
||||
if (!a || !fs.existsSync(file) || !(await ads.milestonesOf(a.email)).includes(key)) { res.writeHead(404, baseHeaders({ 'Content-Type': 'text/plain' })); return res.end('Not found'); }
|
||||
if (!a || !fs.existsSync(file) || !(await badgesHeld(a.email)).includes(key)) { res.writeHead(404, baseHeaders({ 'Content-Type': 'text/plain' })); return res.end('Not found'); }
|
||||
const [label, sub] = BADGE_META[key];
|
||||
const esc = t => String(t || '').replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));
|
||||
const url = SITE_URL + '/b/' + un + '/' + key, img = SITE_URL + '/badge-img/' + un + '/' + key + '.jpg';
|
||||
|
||||
Reference in New Issue
Block a user