Payment proof + transparency (Marty 2026-11-13): every spot sale posts ONE message to the group's payments topic (tgproof.js: buyer, each member paid with POL and $ at the contract's price, company + fund line, Polygonscan verify + live ledger links; once across app copies via docstore.claim; never older than 2 h). New /ledger (every sale and payout, live, verify links) and /contract (verified source, owner, keeper, fee wallets, price feed, live reads, fixed split, how to check). Live sale toasts bottom-left on every page (real ledger rows only, newest 30 min). Nav + footer links. common.js?v=3, line.css?v=5. Smoke 76/76.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-13 10:35:08 -06:00
parent c6ca40a241
commit 87354e29b6
14 changed files with 259 additions and 15 deletions
+41 -2
View File
@@ -14,6 +14,7 @@ const safety = require('./safety');
const keeper = require('./keeper');
const { iface } = require('./abi');
const refuelspots = require('./refuelspots'); // refuel spots: $50+ Monthly Refuels earn a spot, engine wallet pays (2026-11-13)
const tgproof = require('./tgproof'); // payment proof in the Telegram payments topic, one message per spot sale (2026-11-13)
const hubreport = require('./hubreport'); // network hub, shadow mode: members reported by wallet (2026-11-13), off unless HUB_ENABLED
const networksso = require('./networksso'); // network sign-in: arrive signed in from InstantAdPay or LinkSpin (2026-11-13), see networksso.js
const SEL = { buy: iface.getFunction('buy').selector, buyFor: iface.getFunction('buyFor').selector }; // the browser builds calldata from these (ABI stays in abi.js)
@@ -103,6 +104,27 @@ async function lsSpins(body) {
const j = await r.json().catch(() => ({})); return r.ok ? j : { error: j.error || 'LinkSpin did not answer.' };
} catch (e) { return { error: 'LinkSpin did not answer. Try again in a minute.' }; } finally { clearTimeout(t); }
}
// ---- live ledger: chain events grouped into one row per spot sale ----
async function ledgerData(n) {
const evs = chain.recent(5000); const byTx = new Map();
for (const e of evs.slice().reverse()) { if (!['SpotBought', 'Paid', 'PaymentFailed', 'FundBuy'].includes(e.type)) continue; if (!byTx.has(e.tx)) byTx.set(e.tx, []); byTx.get(e.tx).push(e); }
const fee = new Set(['0x7627fc78876948ac9d95c1c9eb061e7d6d647b70', '0x8b7d33849a2c4d92c985be31e46dc564ba901ad2', String(C.contract).toLowerCase()]);
const items = [];
for (const [tx, list] of [...byTx].reverse()) {
const sb = list.find(e => e.type === 'SpotBought'); if (!sb) continue;
let level = 0, house = 0n; const pays = [];
for (const e of list) {
if (e.type !== 'Paid' && e.type !== 'PaymentFailed') continue;
if (e.role === 1) level++;
if (e.type === 'Paid' && (fee.has(e.to) || e.role >= 2)) { house += BigInt(e.amount); continue; }
pays.push({ role: e.role === 0 ? 'sponsor' : 'line', level: e.role === 1 ? level : null, to: e.to, name: await nameOf(e.to).catch(() => null), wei: e.amount, failed: e.type === 'PaymentFailed' });
}
items.push({ tx, at: sb.ts || null, spotId: sb.id, kind: sb.kind, owner: sb.owner, ownerName: await nameOf(sb.owner).catch(() => null), valueWei: sb.valueWei, usd: Number(sb.usdPrice) / 1e8, pays, houseWei: house.toString() });
if (items.length >= n) break;
}
let fund = null; try { const f = await chain.tryRead('fundBalance'); fund = f == null ? null : f.toString(); } catch (e) {}
return { items, totals: Object.assign(chain.totals(), { fundWei: fund }), explorer: C.explorer, contract: C.contract };
}
// ---- sponsor ref (?ref=<address or network username>) ----
async function resolveRef(raw) {
const r = String(raw || '').trim();
@@ -195,7 +217,7 @@ const server = http.createServer(async (req, res) => {
// -- pages
if (req.method === 'GET' || req.method === 'HEAD') {
const PAGES = { '/': 'index.html', '/board': 'board.html', '/join': 'join.html', '/my': 'my.html', '/how': 'how.html' };
const PAGES = { '/': 'index.html', '/board': 'board.html', '/join': 'join.html', '/my': 'my.html', '/how': 'how.html', '/ledger': 'ledger.html', '/contract': 'contract.html' };
if (PAGES[p]) {
const set = [];
if (setVid) set.push(setVid);
@@ -237,6 +259,21 @@ const server = http.createServer(async (req, res) => {
return json(res, 200, { site: C.site, chainId: C.chainId, chainName: C.chainName, contract: C.contract, rpc: C.publicRpc, explorer: C.explorer,
walletConnectProjectId: C.walletConnectProjectId, viewsOwed: C.viewsOwed, spotDays: C.spotDays, priceUsd: 5, ready: !!C.contract, sel: SEL }, extra);
}
// live ledger (Marty 2026-11-13): every spot sale as one row with its payouts, straight from the chain index; the toasts read it too
if (p === '/api/ledger' && req.method === 'GET') {
const n = Math.min(200, Math.max(1, Number(u.searchParams.get('n')) || 50));
return json(res, 200, await ledgerData(n), { 'Cache-Control': 'public, max-age=10' });
}
// contract proof: the live contract's own answers, so anyone can compare them with Polygonscan
if (p === '/api/contract' && req.method === 'GET') {
const r = async f => { const v = await chain.tryRead(f); return v == null ? null : (typeof v === 'bigint' ? v.toString() : String(v).toLowerCase()); };
const [owner, keeper, feeA, feeB, priceFeed, paused, spotCount, fundBalance, quoteWei] = await Promise.all(['owner', 'keeper', 'feeA', 'feeB', 'priceFeed', 'paused', 'spotCount', 'fundBalance', 'quoteWei'].map(r));
return json(res, 200, { address: C.contract, chain: C.chainName, chainId: C.chainId, explorer: C.explorer, verified: true,
deployTx: '0xbe0c76a0999af2b81cd73b69afbe168f08003afdb27dd4ed7be026943e23046d', deployBlock: Number(process.env.START_BLOCK) || null,
owner, keeper, feeA, feeB, priceFeed, paused, spotCount, fundBalance, quoteWei,
split: [{ share: '30%', to: "the buyer's sponsor (none: the momentum fund)" }, { share: '55%', to: '5.5% to each of the 10 spots bought just before (a missing spot: company A)' },
{ share: '5%', to: 'company A' }, { share: '5%', to: 'company B' }, { share: '5%', to: 'the momentum fund (can only buy spots)' }] }, { 'Cache-Control': 'public, max-age=30' });
}
if (p === '/api/quote' && req.method === 'GET') {
try { return json(res, 200, await chain.quote()); } catch (e) { return json(res, 503, { error: e.message }); }
}
@@ -389,7 +426,9 @@ const server = http.createServer(async (req, res) => {
await docstore.init({}); // before anything reads its data
process.on('SIGTERM', () => { docstore.drain(8000).finally(() => process.exit(0)); });
store.load();
chain.init();
tgproof.init({ nameOf, contract: C.contract, explorer: C.explorer || 'https://polygonscan.com', site: C.site,
feeWallets: ['0x7627fc78876948ac9d95c1c9eb061e7d6d647b70', '0x8b7d33849a2c4d92c985be31e46dc564ba901ad2'] }); // contract feeA / feeB
chain.init({ onEvent: tgproof.onEvent }); // every spot sale -> one payment-proof message in the payments topic
hubreport.init({ dataDir: C.dataDir, members: () => chain.allMembers() });
refuelspots.init({ lock: () => keeper.busy() }); keeper.setOtherBusy(() => refuelspots.busy());
keeper.init();