// Stack POL (stackpol.com), 2026-11-09. Marty: build it out before LinkSpin's Nov 15 launch, its own blog on the same engine, // full SEO footprint. Every POL payout across the network, stacked: a network home with live totals, one page per program, // the public ledger (every row links to Polygonscan), opt-in member stacks at /, and the blog. // Data: tools/indexer.py on core reads every program's payout records and IAP/LinkSpin's chain index every 5 minutes and POSTs // one JSON snapshot to /api/ingest (Bearer STACK_INGEST_KEY). Pages read that snapshot, never the chain. The last snapshot is // kept in /tmp so a restart serves numbers at once; the next push replaces it within 5 minutes. 'use strict'; const http = require('http'); const fs = require('fs'); const path = require('path'); const zlib = require('zlib'); const { SITE, esc, head, tail } = require('./layout'); const { PROGRAMS, BY_KEY, BY_SLUG } = require('./programs'); const blog = require('./blog'); const PORT = Number(process.env.PORT) || 80; const KEY = String(process.env.STACK_INGEST_KEY || '').trim(); const OWNER = 'martbost'; // the network pages' join links (the site owner's referral) const SNAP = '/tmp/stack-index.json'; const PUB = path.join(__dirname, 'public'); let IDX = null; try { IDX = JSON.parse(fs.readFileSync(SNAP, 'utf8')); } catch (e) {} blog.load(); const fmt = n => Number(n || 0).toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); const fmtInt = n => Number(n || 0).toLocaleString('en-US'); const ago = ts => { const s = Math.max(0, (Date.now() - ts) / 1000); return s < 90 ? 'just now' : s < 5400 ? Math.round(s / 60) + ' min ago' : s < 129600 ? Math.round(s / 3600) + ' h ago' : Math.round(s / 86400) + ' days ago'; }; const when = ts => new Date(ts).toLocaleString('en-US', { month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit', timeZone: 'America/Chicago' }) + ' CT'; const shortTx = tx => tx ? tx.slice(0, 10) + '…' + tx.slice(-4) : ''; const RESERVED = new Set(['blog', 'ledger', 'programs', 'earn', 'api', 'img', 'sitemap', 'robots', 'favicon', 'about', 'admin', 'login', 'join', 'feed', 'www', 'static', 'assets']); const net = () => (IDX && IDX.network) || { pol: 0, payments: 0, wallets: 0 }; const prog = k => (IDX && IDX.programs && IDX.programs[k]) || { pol: 0, payments: 0, wallets: 0 }; const live = () => IDX ? '
Ledger refreshed ' + ago(IDX.at) + '
' : '
Ledger warming up
'; const seasonOn = p => !p.season || Date.parse(p.season.ends + 'T23:59:59-06:00') >= Date.now(); function card(p, amt, pays, ref, opts) { opts = opts || {}; return '
' + esc(p.n) + ': ' + esc(p.kind) + '
' + esc(p.kind) + '
' + '
' + fmt(amt) + 'POL' + fmtInt(pays) + ' ' + (opts.label || 'payments') + '

' + esc(p.d) + '

' + '' + (p.k === 'iap' || p.k === 'ls' ? 'Join ' + esc(p.n) + ' free' : 'Play ' + esc(p.n) + ' free') + '
'; } function feature(p, ref) { return '
' + esc(p.n) + '
This season

' + esc(p.n) + '

' + esc(p.d) + '

' + esc(p.season.label) + 'Play ' + esc(p.n) + ' free
'; } function ledgerRows(rows, showWho) { if (!rows || !rows.length) return 'The ledger fills in on the next refresh.'; return rows.map(r => { const p = BY_KEY[r.k] || { n: r.k, c: '#888' }; return '' + esc(p.n) + '' + (showWho ? '' + (r.u ? '@' + esc(r.u) + '' : 'a member') + '' : '') + '' + fmt(r.pol) + ' POL' + when(r.ts) + '' + (r.tx ? '' + shortTx(r.tx) + ' ↗' : '') + ''; }).join(''); } const tableHead = showWho => '
' + (showWho ? '' : '') + ''; const heroVideo = ''; const videoJs = ''; const sortedProgs = () => PROGRAMS.slice().sort((a, b) => prog(b.k).pol - prog(a.k).pol); const FAQ = [ ['What is Stack POL?', 'Stack POL adds up every POL payout from the programs in the Crypto Team Build Network: InstantAdPay, LinkSpin and the games that pay POL. The network page shows everyone combined; a member who switches it on gets their own page with their own stack.'], ['Where do the numbers come from?', 'From each program\'s own payout records and from the InstantAdPay and LinkSpin smart contracts on Polygon. Every row in the ledger links to its Polygon transaction, so anyone can check it on Polygonscan.'], ['Is this income? Will I earn this much?', 'No promise of income is made. The totals are what the whole network has paid out so far. What one member stacks depends on what they do, and many members earn little or nothing.'], ['What is POL?', 'POL is the native token of the Polygon network, formerly MATIC. Fees are a fraction of a cent and transfers confirm in seconds, which is why small payouts work on it.'], ['How do I get my own Stack POL page?', 'Join InstantAdPay free, link a wallet, and switch on "Show my Stack POL page" in Promo tools. Your page lives at stackpol.com/your-username and updates every 5 minutes.'], ['Does Stack POL hold my money?', 'No. Stack POL only shows payouts. Every payment goes straight from the program to your own wallet on Polygon.'] ]; function home() { const n = net(), ps = sortedProgs(), feat = ps.filter(p => p.season && seasonOn(p)), rest = ps.filter(p => !(p.season && seasonOn(p))), live7 = IDX && IDX.last7 ? IDX.last7 : null; const ld = [{ '@context': 'https://schema.org', '@type': 'WebSite', name: 'Stack POL', url: SITE + '/', description: 'Every POL payout across the network, stacked in one place.' }, { '@context': 'https://schema.org', '@type': 'Organization', name: 'Stack POL', url: SITE + '/', logo: SITE + '/apple-touch-icon.png', sameAs: ['https://instantadpay.com', 'https://linkspin.app'] }, { '@context': 'https://schema.org', '@type': 'FAQPage', mainEntity: FAQ.map(([q, a]) => ({ '@type': 'Question', name: q, acceptedAnswer: { '@type': 'Answer', text: a } })) }]; let h = head({ title: 'Stack POL: Every POL Payout Across the Network, in One Place', desc: 'See every POL payout from InstantAdPay, LinkSpin and ' + (PROGRAMS.length - 2) + ' games that pay on Polygon. ' + fmt(n.pol) + ' POL paid in ' + fmtInt(n.payments) + ' payments so far, each one checkable on Polygonscan.', path: '/', nav: '/', jsonld: ld }); h += live(); h += '

Paid straight to members\' wallets

Every POL the network pays, stacked in one place

'; h += '
' + fmt(n.pol) + 'POL
Paid by ' + PROGRAMS.length + ' programs, every payment on Polygon
'; h += '
' + fmtInt(n.payments) + 'payments
' + fmtInt(n.wallets) + 'wallets paid
' + (live7 ? '
' + fmt(live7.pol) + 'POL in the last 7 days
' : '') + '
'; h += '
' + ps.filter(p => prog(p.k).pol > 0).map(p => '').join('') + '
'; h += '
' + ps.filter(p => prog(p.k).pol > 0).map(p => '' + esc(p.n) + ' ' + fmt(prog(p.k).pol) + '').join('') + '
'; h += '
Start your own stack, freeFree to join. Network totals, not a promise. What you stack depends on what you do.
' + heroVideo + '
'; h += '

Where the POL comes from

Each program pays straight to your own wallet. See all programs

'; h += feat.map(p => feature(p, OWNER)).join('') + '
' + rest.map(p => card(p, prog(p.k).pol, prog(p.k).payments, OWNER)).join('') + '
'; h += '

Latest payouts on the ledger

Refreshed every 5 minutes. Open the full ledger

' + tableHead(true) + ledgerRows(((IDX && IDX.recent) || []).slice(0, 15), true) + '
ProgramMemberAmountWhenPolygon transaction
'; const posts = blog.listPublished().slice(0, 3); if (posts.length) h += '

From the blog

All posts

' + posts.map(blog.cardHtml).join('') + '
'; h += '

Questions

' + FAQ.map(([q, a]) => '
' + esc(q) + '

' + esc(a) + '

').join('') + '
'; return h + tail(videoJs); } function programsPage() { const ps = sortedProgs(); const ld = [{ '@context': 'https://schema.org', '@type': 'ItemList', name: 'Programs that pay POL in the network', itemListElement: ps.map((p, i) => ({ '@type': 'ListItem', position: i + 1, name: p.n, url: SITE + '/earn/' + p.slug })) }]; let h = head({ title: 'Programs That Pay POL: Games, Ads and Link Tools | Stack POL', desc: 'Every program in the network that pays POL on Polygon, with what each has paid so far: InstantAdPay, LinkSpin, PolHunter, Gem Kingdom, SpellWheel, ClutterHunt and more.', path: '/programs', nav: '/programs', jsonld: ld }); h += '

' + PROGRAMS.length + ' programs

Programs that pay POL

Ad platforms, link tools and games. Each one pays straight to your own wallet on Polygon, and every payout shows up on the ledger.

'; h += '
' + ps.map(p => card(p, prog(p.k).pol, prog(p.k).payments, OWNER)).join('') + '
'; return h + tail(); } function programPage(p) { const s = prog(p.k), rows = ((IDX && IDX.progRecent && IDX.progRecent[p.k]) || ((IDX && IDX.recent) || []).filter(r => r.k === p.k)).slice(0, 20); const desc = p.n + ' pays POL on Polygon. ' + fmt(s.pol) + ' POL paid in ' + fmtInt(s.payments) + ' payments to ' + fmtInt(s.wallets) + ' wallets so far. ' + p.d.slice(0, 90); const ld = [{ '@context': 'https://schema.org', '@type': 'BreadcrumbList', itemListElement: [{ '@type': 'ListItem', position: 1, name: 'Stack POL', item: SITE + '/' }, { '@type': 'ListItem', position: 2, name: 'Programs', item: SITE + '/programs' }, { '@type': 'ListItem', position: 3, name: p.n, item: SITE + '/earn/' + p.slug }] }, p.k === 'iap' || p.k === 'ls' ? { '@context': 'https://schema.org', '@type': 'WebApplication', name: p.n, url: p.site, applicationCategory: 'BusinessApplication', operatingSystem: 'Web', offers: { '@type': 'Offer', price: '0', priceCurrency: 'USD' } } : { '@context': 'https://schema.org', '@type': 'VideoGame', name: p.n, url: p.site, genre: p.kind, gamePlatform: 'Web browser', playMode: 'SinglePlayer', offers: { '@type': 'Offer', price: '0', priceCurrency: 'USD' } }]; let h = head({ title: p.n + ': How It Pays POL, and What It Has Paid So Far | Stack POL', desc, path: '/earn/' + p.slug, image: '/img/' + p.k + '.jpg', imageAlt: p.n, nav: '/programs', jsonld: ld }); h += '

Stack POL / Programs / ' + esc(p.n) + '

'; h += '

' + esc(p.kind) + '

' + esc(p.n) + '

' + esc(p.d) + '

'; h += '
' + fmt(s.pol) + 'POL
' + fmtInt(s.payments) + 'payments
' + fmtInt(s.wallets) + 'wallets paid
' + (s.last ? '
' + ago(s.last) + 'last payout
' : '') + '
'; if (p.season) h += '

' + esc(p.season.label) + '

'; h += '
'; h += '
'; h += '

How ' + esc(p.n) + ' pays

' + esc(p.how || ('Rewards are sent in POL from ' + p.n + '\'s own payout wallet straight to the wallet on your account, on the Polygon network. Every payment is a public transaction you can open on Polygonscan.')) + '

'; h += '

Latest ' + esc(p.n) + ' payouts

All of them

' + tableHead(true) + ledgerRows(rows, true) + ''; const posts = blog.listPublished().filter(b => b.tags.includes(p.slug) || b.tags.includes(p.n.toLowerCase())).slice(0, 3); if (posts.length) h += '

Guides

' + posts.map(blog.cardHtml).join('') + '
'; h += '

More programs that pay POL

' + sortedProgs().filter(x => x.k !== p.k).slice(0, 3).map(x => card(x, prog(x.k).pol, prog(x.k).payments, OWNER)).join('') + '
'; return h + tail(); } function ledgerPage(k) { const p = k && BY_KEY[k]; const rows = ((IDX && IDX.recent) || []).filter(r => !p || r.k === p.k); let h = head({ title: (p ? p.n + ' Payout Ledger' : 'The POL Payout Ledger') + ': Every Payment on Polygon | Stack POL', desc: 'The latest POL payouts across the network' + (p ? ' from ' + p.n : '') + ', each linked to its Polygon transaction. Refreshed every 5 minutes.', path: p ? '/ledger?p=' + p.k : '/ledger', nav: '/ledger', noindex: !!p }); h += live() + '

Public and checkable

The payout ledger

The latest ' + rows.length + ' payouts' + (p ? ' from ' + esc(p.n) : ' across the network') + '. Members who switched on their Stack POL page show by name; everyone else shows as "a member". Every row links to its transaction on Polygonscan.

'; h += '
All' + sortedProgs().map(x => '' + esc(x.n) + '').join('') + '
'; h += tableHead(true) + ledgerRows(rows, true) + ''; return h + tail(); } function stackPage(u, st) { const ps = PROGRAMS.filter(p => st.byProg[p.k]).sort((a, b) => st.byProg[b.k].pol - st.byProg[a.k].pol); const since = st.since ? new Date(st.since).toLocaleDateString('en-US', { month: 'long', year: 'numeric', timeZone: 'America/Chicago' }) : ''; const ld = [{ '@context': 'https://schema.org', '@type': 'ProfilePage', name: '@' + u + ' on Stack POL', url: SITE + '/' + u, mainEntity: { '@type': 'Person', alternateName: u } }]; let h = head({ title: '@' + u + '\'s POL Stack: ' + fmt(st.total) + ' POL From ' + ps.length + ' Programs | Stack POL', desc: '@' + u + ' has stacked ' + fmt(st.total) + ' POL from ' + ps.length + ' programs in the network, every payment on Polygon. Start your own stack free.', path: '/' + u, type: 'profile', jsonld: ld }); h += live() + '
' + esc(u[0].toUpperCase()) + '
@' + esc(u) + '' + (since ? 'Stacking POL since ' + since : 'Stacking POL') + '

Paid straight to one wallet

'; h += '
' + fmt(st.total) + 'POL
From ' + ps.length + ' programs, ' + fmtInt(st.payments) + ' payments on Polygon
'; h += '
' + ps.map(p => '').join('') + '
' + ps.map(p => '' + esc(p.n) + ' ' + fmt(st.byProg[p.k].pol) + '').join('') + '
'; h += '
Start your own stack, freeFree to join. One member\'s results, not a promise. What you stack depends on what you do.
' + heroVideo + '
'; const feat = PROGRAMS.filter(p => p.season && seasonOn(p)), rest = PROGRAMS.filter(p => !(p.season && seasonOn(p))).sort((a, b) => ((st.byProg[b.k] || {}).pol || 0) - ((st.byProg[a.k] || {}).pol || 0)); h += '

Where @' + esc(u) + '\'s POL comes from

Tap any program to start. Each pays to your own wallet.

' + feat.map(p => feature(p, u)).join('') + '
' + rest.map(p => card(p, (st.byProg[p.k] || {}).pol || 0, (st.byProg[p.k] || {}).payments || 0, u)).join('') + '
'; h += '

@' + esc(u) + '\'s latest payouts

' + tableHead(false) + ledgerRows(st.recent || [], false) + ''; return h + tail(videoJs); } function notFound(msg) { return head({ title: 'Not found | Stack POL', desc: 'This page is not on Stack POL.', path: '/404', noindex: true }) + '

Nothing stacked here

' + esc(msg || 'That page does not exist.') + '

Go to Stack POL

' + tail(); } function sitemap() { const d = new Date().toISOString().slice(0, 10); const u = [['/', 'daily', '1.0'], ['/programs', 'daily', '0.9'], ['/ledger', 'hourly', '0.8'], ['/blog', 'daily', '0.9']].map(([p, f, pr]) => '' + SITE + p + '' + d + '' + f + '' + pr + '').join('') + PROGRAMS.map(p => '' + SITE + '/earn/' + p.slug + '' + d + 'daily0.8').join('') + blog.listPublished().map(p => '' + SITE + '/blog/' + p.slug + '' + new Date(p.updated).toISOString().slice(0, 10) + 'monthly0.7').join('') + Object.keys((IDX && IDX.stacks) || {}).map(x => '' + SITE + '/' + x + 'daily0.5').join(''); return '' + u + ''; } const robots = () => 'User-agent: *\nAllow: /\nDisallow: /api/\n\nSitemap: ' + SITE + '/sitemap.xml\n'; const TYPES = { '.jpg': 'image/jpeg', '.png': 'image/png', '.svg': 'image/svg+xml', '.mp4': 'video/mp4', '.webmanifest': 'application/manifest+json', '.ico': 'image/x-icon', '.txt': 'text/plain; charset=utf-8', '.xml': 'application/xml' }; function send(req, res, code, type, body, cache) { const h = { 'Content-Type': type, 'Cache-Control': cache || 'public, max-age=60', 'X-Content-Type-Options': 'nosniff', 'Referrer-Policy': 'strict-origin-when-cross-origin' }; if (/gzip/.test(req.headers['accept-encoding'] || '') && /text|xml|json|javascript/.test(type) && body.length > 1024) { h['Content-Encoding'] = 'gzip'; h.Vary = 'Accept-Encoding'; body = zlib.gzipSync(body); } res.writeHead(code, h); res.end(req.method === 'HEAD' ? undefined : body); } const html = (req, res, code, body, cache) => send(req, res, code, 'text/html; charset=utf-8', body, cache); function staticFile(req, res, p) { const f = path.normalize(path.join(PUB, p)); if (!f.startsWith(PUB)) return false; let st; try { st = fs.statSync(f); } catch (e) { return false; } if (!st.isFile()) return false; const type = TYPES[path.extname(f).toLowerCase()] || 'application/octet-stream'; if (type === 'video/mp4' && req.headers.range) { // seeking support for the hero video const m = /bytes=(\d*)-(\d*)/.exec(req.headers.range); const s = m && m[1] ? Number(m[1]) : 0, e = m && m[2] ? Number(m[2]) : st.size - 1; res.writeHead(206, { 'Content-Type': type, 'Content-Range': 'bytes ' + s + '-' + e + '/' + st.size, 'Accept-Ranges': 'bytes', 'Content-Length': e - s + 1, 'Cache-Control': 'public, max-age=604800' }); return fs.createReadStream(f, { start: s, end: e }).pipe(res), true; } res.writeHead(200, { 'Content-Type': type, 'Content-Length': st.size, 'Cache-Control': 'public, max-age=604800', 'Accept-Ranges': 'bytes' }); if (req.method === 'HEAD') res.end(); else fs.createReadStream(f).pipe(res); return true; } const server = http.createServer((req, res) => { let u; try { u = new URL(req.url, SITE); } catch (e) { res.writeHead(400); return res.end(); } const p = decodeURIComponent(u.pathname); if ((req.headers.host || '').startsWith('www.')) { res.writeHead(301, { Location: SITE + req.url }); return res.end(); } try { if (p === '/api/ingest' && req.method === 'POST') { if (!KEY || req.headers.authorization !== 'Bearer ' + KEY) { res.writeHead(401); return res.end(); } const chunks = []; let n = 0; req.on('data', c => { n += c.length; if (n > 8e6) req.destroy(); else chunks.push(c); }); req.on('end', () => { try { const j = JSON.parse(Buffer.concat(chunks).toString('utf8')); if (!j || !j.network || !j.programs) throw new Error('shape'); j.at = j.at || Date.now(); IDX = j; fs.writeFile(SNAP, JSON.stringify(j), () => {}); send(req, res, 200, 'application/json', JSON.stringify({ ok: true, at: j.at }), 'no-store'); } catch (e) { send(req, res, 400, 'application/json', JSON.stringify({ error: e.message }), 'no-store'); } }); return; } if (req.method !== 'GET' && req.method !== 'HEAD') { res.writeHead(405); return res.end(); } if (p === '/api/totals') return send(req, res, 200, 'application/json', JSON.stringify({ at: IDX ? IDX.at : null, network: net(), programs: (IDX && IDX.programs) || {} }), 'public, max-age=120'); if (p === '/health') return send(req, res, 200, 'text/plain', 'ok', 'no-store'); if (p === '/') return html(req, res, 200, home(), 'public, max-age=120'); if (p === '/programs') return html(req, res, 200, programsPage(), 'public, max-age=300'); if (p === '/ledger') return html(req, res, 200, ledgerPage(u.searchParams.get('p')), 'public, max-age=120'); let m = /^\/earn\/([a-z0-9-]+)\/?$/.exec(p); if (m) return BY_SLUG[m[1]] ? html(req, res, 200, programPage(BY_SLUG[m[1]]), 'public, max-age=300') : html(req, res, 404, notFound()); if (p === '/blog' || p === '/blog/') return html(req, res, 200, blog.renderIndex(1)); m = /^\/blog\/page\/(\d+)$/.exec(p); if (m) return html(req, res, 200, blog.renderIndex(Number(m[1]))); m = /^\/blog\/tag\/([^/]+)$/.exec(p); if (m) return html(req, res, 200, blog.renderIndex(1, m[1].toLowerCase())); if (p === '/blog/feed.xml') return send(req, res, 200, 'application/rss+xml; charset=utf-8', blog.rss(), 'public, max-age=600'); m = /^\/blog\/([a-z0-9-]+)\/?$/.exec(p); if (m) { const post = blog.get(m[1]); return post ? html(req, res, 200, blog.renderPost(post), 'public, max-age=600') : html(req, res, 404, notFound('That post is not here.')); } if (p === '/sitemap.xml') return send(req, res, 200, 'application/xml; charset=utf-8', sitemap(), 'public, max-age=3600'); if (p === '/robots.txt') return send(req, res, 200, 'text/plain; charset=utf-8', robots(), 'public, max-age=86400'); if (staticFile(req, res, p)) return; m = /^\/@?([a-z0-9_]{3,30})\/?$/i.exec(p); if (m && !RESERVED.has(m[1].toLowerCase())) { const name = m[1].toLowerCase(), st = IDX && IDX.stacks && IDX.stacks[name]; if (st) return html(req, res, 200, stackPage(name, st), 'public, max-age=120'); return html(req, res, 404, notFound('@' + name + ' has not switched on a Stack POL page yet. Members turn it on in InstantAdPay Promo tools.')); } return html(req, res, 404, notFound()); } catch (e) { console.error('[stackpol]', p, e); html(req, res, 500, notFound('Something went wrong on our side. Try again in a minute.'), 'no-store'); } }); server.listen(PORT, () => console.log('Stack POL on :' + PORT + ' | snapshot ' + (IDX ? new Date(IDX.at).toISOString() : 'none yet') + ' | posts ' + blog.listPublished().length + ' | ingest ' + (KEY ? 'on' : 'OFF (no STACK_INGEST_KEY)')));