diff --git a/.env.example b/.env.example
index 8970e0a..a59719a 100644
--- a/.env.example
+++ b/.env.example
@@ -30,6 +30,8 @@ SHOP_START_BLOCK= # the deploy block; the first scan starts here
SHOP_CONFIRMATIONS=10 # credit only this many blocks behind the head
SHOP_POLL_MS=30000
KEEPER_KEY= # private key of the contract's keeper (signs sponsor vouchers). Coolify secret only, never in git
+PRIZE_KEY= # private key of the prize wallet (weekly payouts, sent only when an admin approves). Coolify secret only, never in git
+PRIZE_WALLET= # default 0x167315726Fe50CFF97b8F4c91c8C606489397907; must equal VBBShop.prizeWallet()
VOUCHER_SECONDS=1800 # a voucher is good for 30 minutes
# Network hub report (hubreport.js): every VBBShop purchase reported by wallet (bind, then spend). Off unless HUB_ENABLED=1.
HUB_URL= # https://hub.saasy.top
diff --git a/config.js b/config.js
index 3a1665f..89ee015 100644
--- a/config.js
+++ b/config.js
@@ -1,6 +1,7 @@
// All runtime config comes from env (Coolify sets these). Read once.
-// VBB v1 takes no payments in the UI: planned prices show as "coming soon"; rewards are recorded, not credited yet. The VBBShop
-// contract hooks (shop.js: sponsor vouchers + purchase watcher) stay inert until CONTRACT_ADDRESS / CHAIN_RPC / KEEPER_KEY are set.
+// Purchases are live through VBBShop (2026-11-14): the packages page and My Banners sell packs and banner looks from the member's
+// wallet; shop.js signs sponsor vouchers, builds the buy() call and credits from Purchase events. Inert until CONTRACT_ADDRESS /
+// CHAIN_RPC / KEEPER_KEY are set. Weekly prize payouts: prize.js (two-step admin flow, PRIZE_KEY read there only).
const path = require('path');
let cfg = null;
@@ -31,15 +32,18 @@ function get() {
freeCreditsPerDay: num(e.FREE_CREDITS_PER_DAY, 1, 0, 10), // Marty 2026-11-13: 1 free post credit a day on sign-in
freeCreditCap: num(e.FREE_CREDIT_CAP, 7, 1, 365), // daily free credits bank up to this many
maxQueuedPerMember: num(e.MAX_QUEUED_PER_MEMBER, 3, 1, 100), // banners one member may have waiting at once
- // ---- Marty's approved numbers (2026-11-13). v1 takes no payments: packages show as "coming soon" with these planned prices,
- // prizes are displayed only (no payout code yet), the split is kept here for the contract step.
- packs: list(e.CREDIT_PACKS, '10:3,40:10').map(x => { const [credits, usd] = x.split(':').map(Number); return { credits, usd }; }).filter(x => x.credits > 0 && x.usd > 0),
+ // ---- Marty's approved numbers (2026-11-13), sold on chain through VBBShop since 2026-11-14 (the contract's SKUs hold the real
+ // prices; these are the display copy and must match them). Pack n is SKU PACK_SKUS[n]; the banner look is LOOK_SKU.
+ packs: list(e.CREDIT_PACKS, '10:3,40:10').map((x, i) => { const [credits, usd] = x.split(':').map(Number); return { credits, usd, sku: Number(list(e.PACK_SKUS, '1,2')[i]) || i + 1 }; }).filter(x => x.credits > 0 && x.usd > 0),
+ lookSku: num(e.LOOK_SKU, 3, 1, 1000),
lookUsd: Number(e.LOOK_USD || 2), // banner look (border + hover teaser), per banner, one-time
split: { sponsorPct: num(e.SPONSOR_PCT, 30, 0, 100), companyPct: 100 - num(e.SPONSOR_PCT, 30, 0, 100) }, // on-chain later, no line
// weekly prize pot (Marty 2026-11-13): 10% of the week's sales, never under the floor (the company tops it up), capped at $50.
// Half the pot per leaderboard, split 50/30/20 across the top three. The cap is internal: the public page never shows it.
prizePot: { pct: num(e.PRIZE_PCT, 10, 0, 100), floorUsd: num(e.PRIZE_FLOOR_USD, 20, 0, 100000), capUsd: num(e.PRIZE_CAP_USD, 50, 0, 100000),
- places: list(e.PRIZE_PLACES, '50,30,20').map(Number).filter(x => x >= 0) },
+ places: list(e.PRIZE_PLACES, '50,30,20').map(Number).filter(x => x >= 0),
+ wallet: /^0x[0-9a-fA-F]{40}$/.test(String(e.PRIZE_WALLET || '').trim()) ? String(e.PRIZE_WALLET).trim().toLowerCase() : '0x167315726fe50cff97b8f4c91c8c606489397907' },
+ explorer: String(e.EXPLORER || (Number(e.CHAIN_ID || 137) === 137 ? 'https://polygonscan.com' : '')).replace(/\/+$/, ''),
// VBBShop (../contracts). KEEPER_KEY is read by shop.js only, never kept here.
contractAddress: /^0x[0-9a-fA-F]{40}$/.test(String(e.CONTRACT_ADDRESS || '').trim()) ? require('ethers').getAddress(String(e.CONTRACT_ADDRESS).trim()) : '',
chainRpc: String(e.CHAIN_RPC || '').trim(), // the watcher's RPC (server side); '' = watcher off
diff --git a/docker-compose.yml b/docker-compose.yml
index 09a28b4..f4713ec 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -16,6 +16,7 @@ services:
CHAIN_RPC: ${CHAIN_RPC:-}
SHOP_START_BLOCK: ${SHOP_START_BLOCK:-}
KEEPER_KEY: ${KEEPER_KEY:-}
+ PRIZE_KEY: ${PRIZE_KEY:-} # the prize wallet's key (weekly payouts, admin-approved); a Coolify secret
CHAIN_ID: ${CHAIN_ID:-137}
RPC_URLS: ${RPC_URLS:-}
HUB_URL: ${HUB_URL:-}
diff --git a/loop.js b/loop.js
index 80646de..adbebb4 100644
--- a/loop.js
+++ b/loop.js
@@ -87,21 +87,25 @@ function verifiedVisit(o) {
}
// ---- weekly leaderboards (Central time, Monday to Sunday) ----
+// Ties (Marty 2026-11-14): whoever reached the count first ranks higher. Visitors: the time of their latest counted visitor.
+// Sources: the time their latest new source first appeared. Both are order-independent (rows may load in any order).
let lbCache = null;
function leaders(week, n) {
const wk = week || store.ctWeek(); n = n || 10;
- if (lbCache && lbCache.wk === wk && Date.now() - lbCache.at < 15000 && lbCache.n === store.visits().length) return lbCache.out;
+ if (lbCache && lbCache.wk === wk && lbCache.n0 === n && Date.now() - lbCache.at < 15000 && lbCache.n === store.visits().length) return lbCache.out;
const per = new Map();
for (const v of store.visits()) {
if (v.wk !== wk || !v.ref) continue;
- const p = per.get(v.ref) || per.set(v.ref, { address: v.ref, visitors: 0, sources: new Set() }).get(v.ref);
- p.visitors++; if (v.src) p.sources.add(v.src);
+ const p = per.get(v.ref) || per.set(v.ref, { address: v.ref, visitors: 0, vAt: 0, src: new Map() }).get(v.ref);
+ p.visitors++; if (v.at > p.vAt) p.vAt = v.at;
+ if (v.src) { const f = p.src.get(v.src); if (!f || v.at < f) p.src.set(v.src, v.at); }
}
- const rows = [...per.values()].map(p => { const m = store.member(p.address); return { address: p.address, username: (m && m.username) || null, visitors: p.visitors, sources: p.sources.size }; });
+ const rows = [...per.values()].map(p => { const m = store.member(p.address);
+ return { address: p.address, username: (m && m.username) || null, visitors: p.visitors, sources: p.src.size, visitorsAt: p.vAt, sourcesAt: p.src.size ? Math.max(...p.src.values()) : 0 }; });
const out = { week: wk,
- visitors: rows.slice().sort((a, b) => b.visitors - a.visitors || b.sources - a.sources).slice(0, n),
- sources: rows.filter(r => r.sources > 0).sort((a, b) => b.sources - a.sources || b.visitors - a.visitors).slice(0, n) };
- lbCache = { wk, at: Date.now(), n: store.visits().length, out };
+ visitors: rows.slice().sort((a, b) => b.visitors - a.visitors || a.visitorsAt - b.visitorsAt).slice(0, n),
+ sources: rows.filter(r => r.sources > 0).sort((a, b) => b.sources - a.sources || a.sourcesAt - b.sourcesAt).slice(0, n) };
+ lbCache = { wk, n0: n, at: Date.now(), n: store.visits().length, out };
return out;
}
function memberWeek(addr) {
@@ -111,7 +115,10 @@ function memberWeek(addr) {
}
// ---- views for pages ----
-function tile(b) { const m = store.member(b.owner); return { id: b.id, img: b.img, href: '/go/' + b.id, owner: (m && m.username) ? '@' + m.username : null }; }
+// the banner look (bought per banner, SKU 3): a highlighted border and a hover teaser (the member's line, else the link's site)
+const hostOf = l => { try { return new URL(l).hostname.replace(/^www\./, ''); } catch (e) { return ''; } };
+function tile(b) { const m = store.member(b.owner); const t = { id: b.id, img: b.img, href: '/go/' + b.id, owner: (m && m.username) ? '@' + m.username : null };
+ if (b.look) { t.look = true; t.teaser = b.teaser || hostOf(b.link); } return t; }
function view(queueShow) {
const S = store.state();
return { loopSize: C().loopSize, perShift: C().perShift, progress: S.progress, waiting: S.queue.length,
@@ -127,4 +134,4 @@ function placeOf(b) {
return { state: b.state };
}
-module.exports = { init, post, shift, verifiedVisit, canCount, rebuildIndex, leaders, memberWeek, view, placeOf, normalize };
+module.exports = { hostOf, init, post, shift, verifiedVisit, canCount, rebuildIndex, leaders, memberWeek, view, placeOf, normalize };
diff --git a/package.json b/package.json
index 2b6f59e..fc62421 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,8 @@
"scripts": {
"start": "node server.js",
"dev": "node --watch server.js",
- "qa": "node qa/smoke.mjs"
+ "qa": "node qa/smoke.mjs",
+ "qa:chain": "node qa/chain.mjs"
},
"engines": {
"node": ">=20"
diff --git a/prize.js b/prize.js
new file mode 100644
index 0000000..9889fd1
--- /dev/null
+++ b/prize.js
@@ -0,0 +1,187 @@
+// Weekly prize payouts (Marty 2026-11-14). Two steps, money rule: the app PREPARES, an admin APPROVES, the app pays once.
+// - The pot of a Central-time week (Monday 12:00 AM to Sunday) = 10% of that week's VBBShop sales (usdCents of the credited
+// Purchase events, by block time; the prize wallet received exactly that share in POL), never under the floor (the company
+// tops the prize wallet up), never over the cap (internal, never shown). Half the pot per leaderboard, 50/30/20 to the top 3.
+// - Winners: the weekly leaderboards (loop.leaders): most verified visitors sent, most distinct traffic sources. Ties: the
+// earlier to reach the count wins. Each VBB account IS a wallet, so the winner's wallet is their account address. A winner
+// that cannot be paid (not a valid wallet, or the prize/company wallet itself) is skipped: everyone below moves up a place, and
+// a place nobody fills is not paid (its share stays in the prize wallet for later weeks).
+// - prepare(week): every 10 minutes the app prepares the last finished week if it has no plan yet (so Monday after midnight CT).
+// A plan holds the winners, wallets and USD amounts. POL amounts are quoted live from the Chainlink POL/USD feed the contract
+// uses (fresh answer only), and fixed at the moment of payment.
+// - pay(week): admin only. Refuses unless PRIZE_KEY is set and is the contract's prize wallet, the feed is fresh, and the prize
+// wallet holds the POL plus gas (says how much is missing). Once per week, across app copies and restarts (docstore.claim in
+// MySQL, then the plan's own status). Sends one plain POL transfer per winner with consecutive nonces, records each hash at
+// once, stops at the first error (never retried automatically: an unclear send must be checked on the explorer by a person),
+// then watches the receipts. Posts nothing anywhere.
+// Plans live in prizes.json (a MySQL document through docstore). PRIZE_KEY is read here only and never leaves this module.
+'use strict';
+const fs = require('fs');
+const path = require('path');
+const { Wallet, JsonRpcProvider, getAddress } = require('ethers');
+const store = require('./store');
+const loop = require('./loop');
+const shop = require('./shop');
+const docstore = require('./docstore');
+
+const ADDR_RE = /^0x[0-9a-fA-F]{40}$/;
+const BOARDS = ['visitors', 'sources'];
+const COMPANY = '0x7627fc78876948ac9d95c1c9eb061e7d6d647b70';
+let C = null, key = null, D = null, busy = false, timer = null;
+const st = { prepared: 0, paid: 0, lastError: null };
+const FILE = () => path.join(C.dataDir, 'prizes.json');
+
+function init(cfg) {
+ C = cfg; key = null;
+ const k = String(process.env.PRIZE_KEY || '').trim();
+ if (k) { try { key = new Wallet(k.startsWith('0x') ? k : '0x' + k); } catch (e) { console.error('prize: PRIZE_KEY is not a valid private key; payouts off'); } }
+ try { D = JSON.parse(fs.readFileSync(FILE(), 'utf8')); } catch (e) { D = null; }
+ D = Object.assign({ weeks: {} }, D || {});
+ // a payment interrupted by a restart: its receipts are watched again
+ for (const p of Object.values(D.weeks)) if (p.status === 'paying' || p.status === 'sent') watchReceipts(p.week);
+ if (timer) clearInterval(timer);
+ timer = setInterval(() => auto().catch(() => {}), 600000); timer.unref();
+ setTimeout(() => auto().catch(() => {}), 5000).unref();
+}
+function save() { const tmp = FILE() + '.tmp'; fs.writeFileSync(tmp, JSON.stringify(D)); fs.renameSync(tmp, FILE()); }
+const r2 = x => Math.round(x * 100) / 100;
+const nameOf = (addr, username) => username ? '@' + username : addr.slice(0, 6) + '...' + addr.slice(-4);
+// the Monday before `week` (both YYYY-MM-DD)
+const prevWeek = week => new Date(Date.parse(week + 'T12:00:00Z') - 7 * 86400000).toISOString().slice(0, 10);
+
+// the pot of a week from its sales
+function pot(week) {
+ const z = C.prizePot; const s = shop.weekSales(week, store.ctWeek);
+ const raw = s.cents / 100 * z.pct / 100;
+ const usd = Math.min(z.capUsd, Math.max(z.floorUsd, raw));
+ const board = usd / 2;
+ return { salesUsd: r2(s.cents / 100), purchases: s.purchases, prizeShareWei: s.prizeWei, shareUsd: r2(raw), potUsd: r2(usd), atFloor: raw <= z.floorUsd, atCap: raw >= z.capUsd,
+ topUpUsd: r2(Math.max(0, usd - raw)), places: z.places.map(x => r2(board * x / 100)) };
+}
+// the payable winners of one board, in order
+function winners(rows, max) {
+ const out = [], prizeW = C.prizePot.wallet;
+ for (const r of rows) {
+ if (out.length >= max) break;
+ const a = String(r.address || '').toLowerCase();
+ if (!ADDR_RE.test(a) || a === prizeW || a === COMPANY) continue; // skipped: everyone below moves up
+ out.push(r);
+ }
+ return out;
+}
+function prepare(week, force) {
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(String(week || ''))) return { error: 'week must be YYYY-MM-DD (that Monday)' };
+ if (week >= store.ctWeek()) return { error: 'That week has not finished yet (weeks end Sunday midnight, Central time).' };
+ const have = D.weeks[week];
+ if (have && !(force && (have.status === 'prepared' || have.status === 'nothing'))) return have;
+ const pz = pot(week); const lb = loop.leaders(week, 100);
+ const transfers = [];
+ for (const board of BOARDS) {
+ const list = winners(lb[board], pz.places.length);
+ list.forEach((r, i) => transfers.push({ board, place: i + 1, address: r.address.toLowerCase(), name: nameOf(r.address, r.username), count: r[board],
+ reachedAt: board === 'visitors' ? r.visitorsAt : r.sourcesAt, usd: pz.places[i], cents: Math.round(pz.places[i] * 100) }));
+ }
+ const unfilled = BOARDS.reduce((t, b) => t + pz.places.slice(transfers.filter(x => x.board === b).length).reduce((a, v) => a + v, 0), 0);
+ const plan = Object.assign({ week, preparedAt: Date.now(), status: transfers.length ? 'prepared' : 'nothing', transfers, unfilledUsd: r2(unfilled) }, pz,
+ { payUsd: r2(transfers.reduce((t, x) => t + x.usd, 0)) });
+ D.weeks[week] = plan; save(); st.prepared++;
+ console.log('prize: week', week, 'prepared,', transfers.length, 'winners, $' + plan.payUsd, plan.status);
+ return plan;
+}
+// prepare the last finished week once (Monday after midnight CT); never touches a week that already has a plan
+async function auto() { const w = prevWeek(store.ctWeek()); if (!D.weeks[w]) prepare(w); }
+
+// ---- live numbers: the Chainlink POL/USD answer (8 decimals), the prize wallet balance, gas ----
+async function price() {
+ const feed = (await shop.call('priceFeed', []))[0];
+ const r = await shop.call('latestRoundData', [], feed);
+ const answer = BigInt(r[1]), at = Number(r[3]);
+ if (answer <= 0n) throw new Error('The price feed answered zero.');
+ if (Math.floor(Date.now() / 1000) - at > 3600) throw new Error('The POL/USD price feed is older than 1 hour. Try again when it updates.');
+ return { answer, at, usd: Number(answer) / 1e8 };
+}
+const fmtPol = wei => { const s = (BigInt(wei) * 10000n / 10n ** 18n).toString().padStart(5, '0'); return s.slice(0, -4) + '.' + s.slice(-4); };
+async function quotePlan(plan) {
+ const out = { keyOn: !!key, keyAddress: key ? key.address.toLowerCase() : null, prizeWallet: C.prizePot.wallet };
+ try {
+ const onChain = String((await shop.call('prizeWallet', []))[0]).toLowerCase(); out.contractPrizeWallet = onChain;
+ out.keyMatches = !!key && key.address.toLowerCase() === onChain;
+ const p = await price(); out.priceUsd = p.usd; out.priceAt = p.at;
+ const f = await shop.fees(); const maxFee = BigInt(f.maxFeePerGas);
+ let total = 0n; const lines = (plan.transfers || []).map(t => { const wei = BigInt(t.cents) * 10n ** 24n / p.answer; total += wei; return { board: t.board, place: t.place, wei: wei.toString(), pol: fmtPol(wei) }; });
+ const gas = BigInt(lines.length) * 30000n * maxFee; // 21,000 for a wallet, headroom for a contract wallet
+ const bal = BigInt(await shop.rpc('eth_getBalance', [onChain, 'latest']));
+ Object.assign(out, { lines, totalWei: total.toString(), totalPol: fmtPol(total), gasWei: gas.toString(), gasPol: fmtPol(gas), balanceWei: bal.toString(), balancePol: fmtPol(bal),
+ shortWei: (bal >= total + gas ? 0n : total + gas - bal).toString(), shortPol: fmtPol(bal >= total + gas ? 0n : total + gas - bal), maxFeePerGas: f.maxFeePerGas, maxPriorityFeePerGas: f.maxPriorityFeePerGas });
+ } catch (e) { out.error = String(e.message || e).slice(0, 200); }
+ return out;
+}
+
+async function pay(week) {
+ const plan = D.weeks[week];
+ if (!plan) return { error: 'No plan for that week. Prepare it first.' };
+ if (plan.status !== 'prepared') return { error: 'This week is ' + plan.status + '. A week is paid once.' , plan };
+ if (busy) return { error: 'A payout is already running.' };
+ if (!key) return { error: 'PRIZE_KEY is not set on the server.' };
+ busy = true;
+ try {
+ const q = await quotePlan(plan);
+ if (q.error) return { error: q.error };
+ if (!q.keyMatches) return { error: 'PRIZE_KEY is not the contract\'s prize wallet (' + q.contractPrizeWallet + '). Nothing sent.' };
+ if (BigInt(q.shortWei) > 0n) return { error: 'The prize wallet holds ' + q.balancePol + ' POL. This week needs ' + q.totalPol + ' POL plus about ' + q.gasPol + ' POL gas: send at least ' + q.shortPol + ' POL more to ' + q.contractPrizeWallet + '. Nothing sent.', quote: q };
+ // once per week, ever: the MySQL claim first (two app copies during a deploy), then the plan's own status
+ if (!(await docstore.claim('vbb-prize-pay:' + week))) { plan.status = 'claimed-elsewhere'; save(); return { error: 'This week was already claimed for payment (another app copy or an earlier attempt). Nothing sent; check /admin and the prize wallet on the explorer.' }; }
+ plan.status = 'paying'; plan.payment = { startedAt: Date.now(), priceUsd: q.priceUsd, priceAt: q.priceAt, from: q.contractPrizeWallet, totalWei: q.totalWei };
+ plan.transfers.forEach((t, i) => { t.wei = q.lines[i].wei; t.pol = q.lines[i].pol; t.status = 'pending'; });
+ save(); await docstore.drain(5000); // the 'paying' mark is in MySQL before the first POL moves
+ const provider = new JsonRpcProvider(C.chainRpc, C.chainId, { staticNetwork: true });
+ const w = key.connect(provider);
+ let nonce = await provider.getTransactionCount(w.address, 'pending');
+ for (const t of plan.transfers) {
+ try {
+ let gasLimit = 21000n;
+ try { gasLimit = await provider.estimateGas({ from: w.address, to: getAddress(t.address), value: BigInt(t.wei) }); gasLimit = gasLimit * 12n / 10n; if (gasLimit > 30000n) gasLimit = 30000n; if (gasLimit < 21000n) gasLimit = 21000n; } catch (e) {}
+ const tx = await w.sendTransaction({ to: getAddress(t.address), value: BigInt(t.wei), nonce, gasLimit, maxFeePerGas: BigInt(q.maxFeePerGas), maxPriorityFeePerGas: BigInt(q.maxPriorityFeePerGas), chainId: C.chainId, type: 2 });
+ t.tx = tx.hash; t.status = 'sent'; t.sentAt = Date.now(); nonce++; save();
+ console.log('prize: week', week, t.board, '#' + t.place, t.pol, 'POL to', t.address, tx.hash);
+ } catch (e) {
+ // unclear: the transfer may or may not have reached the network. Never resent automatically.
+ t.status = 'unknown'; t.error = String(e.shortMessage || e.message || e).slice(0, 200); st.lastError = t.error;
+ for (const r of plan.transfers) if (r.status === 'pending') r.status = 'not-sent';
+ save(); break;
+ }
+ }
+ plan.status = plan.transfers.every(t => t.status === 'sent') ? 'sent' : 'partial';
+ plan.payment.sentAt = Date.now(); save(); st.paid++;
+ watchReceipts(week);
+ return { ok: true, plan };
+ } finally { busy = false; }
+}
+// receipts: confirmed / reverted per transfer; the week is 'paid' when every transfer confirmed
+const watching = new Set();
+function watchReceipts(week) {
+ if (watching.has(week)) return; watching.add(week);
+ let tries = 0;
+ const tick = async () => {
+ const plan = D.weeks[week]; if (!plan) { watching.delete(week); return; }
+ for (const t of plan.transfers) {
+ if (t.status !== 'sent' || !t.tx) continue;
+ try { const r = await shop.receipt(t.tx); if (r.found) { t.status = r.status === '0x1' ? 'confirmed' : 'reverted'; t.block = parseInt(r.blockNumber, 16); save(); } } catch (e) {}
+ }
+ const open = plan.transfers.some(t => t.status === 'sent');
+ if (!open && (plan.status === 'sent' || plan.status === 'paying')) { plan.status = plan.transfers.every(t => t.status === 'confirmed') ? 'paid' : 'partial'; plan.payment.doneAt = Date.now(); save(); }
+ if (open && ++tries < 240) { const tm = setTimeout(tick, Number(process.env.PRIZE_RECEIPT_MS || 5000)); tm.unref(); } else watching.delete(week);
+ };
+ tick();
+}
+
+// public: weeks with transfers sent, newest first (names, places, USD, POL, transaction links)
+function history(n) {
+ return Object.values(D.weeks).filter(p => p.payment && p.transfers.some(t => t.tx)).sort((a, b) => b.week.localeCompare(a.week)).slice(0, n || 12)
+ .map(p => ({ week: p.week, potUsd: p.potUsd, priceUsd: p.payment.priceUsd, paidAt: p.payment.sentAt || p.payment.startedAt, status: p.status,
+ winners: p.transfers.filter(t => t.tx).map(t => ({ board: t.board, place: t.place, name: t.name, count: t.count, usd: t.usd, pol: t.pol, tx: t.tx, confirmed: t.status === 'confirmed' })) }));
+}
+function plans() { return Object.values(D.weeks).sort((a, b) => b.week.localeCompare(a.week)); }
+function view() { return Object.assign({ keyOn: !!key, keyAddress: key ? key.address.toLowerCase() : null, prizeWallet: C.prizePot.wallet, weeks: Object.keys(D.weeks).length }, st); }
+
+module.exports = { init, pot, prepare, pay, quotePlan, history, plans, view, prevWeek, auto };
diff --git a/public/admin.html b/public/admin.html
index fd19903..52dfdfe 100644
--- a/public/admin.html
+++ b/public/admin.html
@@ -22,20 +22,21 @@
-
+
-
Admin
Loop status and the cycle reward ledger. Rewards are recorded only; nothing is credited yet.
+
Admin
Loop status, weekly prize payouts and the cycle reward ledger. Cycle rewards are recorded only; nothing is credited yet.
Status
+
Weekly prize payouts
Each Monday after midnight (Central) the app prepares last week's payout. Nothing is sent until you approve it here, and a week is paid once. Amounts in POL are quoted live and fixed when you approve.