Level 4 override for LinkSpin: weekly dry-run report + the payer, shipped OFF (Marty approved 2026-10-23)

override.js is the InstantAdPay module (same code, same tests) with LinkSpin defaults: qualification is the
LinkSpin contract's own buyerCount >= 5 (referred first buys of $20+, which on the $10/$25/... ladder means
$25+, the level-3 bar), house id #1, hunt up to 25 hops, one recipient per purchase, purchases from
overrideGoLive on, weekly Mon-Sun Central, settled Monday after 9 AM CT.

- Default overrideMode 'dryrun': Monday who-would-be-paid summary to the admin Telegram chat
  (telegramAdminChatId; email to ADMIN_EMAIL if the bot is not set). No money moves.
- Payer pays only with overrideMode 'live' + overrideGoLive + OVERRIDE_PAYER_KEY. LinkSpin has no MySQL,
  so every once-only step is an exclusive file create on the shared volume (fails closed); plan frozen
  per week, 'sending' persisted before the tx, lost answers -> review (never re-sent), dust carried,
  weekly cap held whole, balance + gas checked first.
- Members: AwardPaid from the payer emails + on-site notice "Your Level 4 override is paid"; Wallet
  screen and feeds label it "Level 4 override". /api/my/activity now reads the whole history (was the
  last 600 events, the IAP bug of 2026-09-16; LinkSpin is at 525).
- Admin: /api/admin/override (+ status, payer), POST /pay (live only), POST /resolve; P&L card.
- Contract page: Level 4 override panel hidden until overrideMode is live (contract.js reveals it).
- qa/override.test.cjs (bash qa/run.sh override): 30 checks, fake chain/signer, throwaway data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-23 15:20:02 -05:00
parent 1c2ef3780c
commit 010c3afdd9
23 changed files with 693 additions and 23 deletions
+9 -2
View File
@@ -466,6 +466,13 @@
<p class="small" id="burnerLine">…</p>
<p><button class="btn small sec" type="button" id="burnerRun">Run now</button></p>
</div>
<div class="card">
<div class="card-head"><h3>Level 4 override</h3><span class="sub">3% of each purchase to the qualified 4th upline, paid weekly from the payer wallet</span></div>
<p class="small" id="ovPayer">…</p>
<div id="ovWeeks" class="small"></div>
<p><select id="ovWeek"></select> <button class="btn small sec" type="button" id="ovShow">Show week</button> <button class="btn small" type="button" id="ovPay" hidden>Pay this week now</button></p>
<div id="ovOut" class="small"></div>
</div>
</div>
<div class="pane" id="pane-settings" hidden>
<div class="card">
@@ -510,8 +517,8 @@
</div>
</div>
<script src="/assets/common.js?v=20261018p25"></script>
<script src="/assets/common.js?v=20261023ov"></script>
<script src="/assets/admin-kb.js?v=20261020kb"></script>
<script src="/assets/admin.js?v=20261023q"></script><script src="/assets/admin-sponsorcheck.js?v=20261022sc"></script>
<script src="/assets/admin.js?v=20261023ov"></script><script src="/assets/admin-sponsorcheck.js?v=20261022sc"></script>
</body>
</html>
+24
View File
@@ -847,6 +847,7 @@
}
async function loadPnl() {
loadOverride().catch(() => {}); // its own request: does not wait for the chain reads below
const r = await api('/api/admin/pnl?days=' + pnlDays);
const px = r.polUsd || 0;
const platUsd = (Number(BigInt(r.platformWei || '0') / 10n ** 14n) / 10000) * px;
@@ -871,6 +872,29 @@
}
document.querySelectorAll('#pnlPeriods [data-days]').forEach(b => b.addEventListener('click', () => { pnlDays = Number(b.dataset.days); document.querySelectorAll('#pnlPeriods [data-days]').forEach(x => x.classList.toggle('on', x === b)); loadPnl().catch(e => IAP.status(e.message, 'bad')); }));
if ($('pnlFixedSave')) $('pnlFixedSave').addEventListener('click', async () => { try { await api('/api/admin/site', { pnlFixedMonthlyUsd: Number($('pnlFixed').value) || 0 }, 'PATCH'); IAP.status('Saved.', 'ok'); loadPnl(); } catch (e) { IAP.status(e.message, 'bad'); } });
// Level 4 override (2026-10-23): week status from /api/admin/override; the pay button exists only while the live payer is ready
const OV_STATE = { 'not planned': 'not planned', planning: 'planning', planned: 'pending', paying: 'paying', held: 'held', paid: 'paid' };
async function loadOverride(week) {
if (!$('ovPayer')) return;
let r; try { r = await (await fetch('/api/admin/override' + (week ? '?week=' + encodeURIComponent(week) : ''), { cache: 'no-store' })).json(); } catch (e) { $('ovPayer').textContent = 'Could not read the override: ' + e.message; return; }
const pz = r.payer || {};
$('ovPayer').textContent = 'Mode: ' + (pz.mode || '?') + (pz.ready ? ' · PAYING automatically each Monday after 9 AM CT' : ' · not paying (' + (pz.why || []).join('; ') + ')')
+ (pz.address ? ' · payer wallet ' + pz.address + ' holds ' + (pz.balancePol || '?') + ' POL' : '') + ' · weekly cap ' + (pz.capPol || '?') + ' POL · minimum ' + (pz.dustPol || '?') + ' POL'
+ (pz.goLive ? ' · purchases from ' + new Date(pz.goLive).toLocaleString('en-US', { timeZone: 'America/Chicago' }) + ' CT' : '') + (pz.lastError ? ' · last error: ' + pz.lastError.msg : '');
$('ovPay').hidden = !pz.ready;
const sel = $('ovWeek'); if (!sel.options.length) { const now = new Date(); for (let i = 0; i < 10; i++) { const d = new Date(now.getTime() - i * 7 * 86400000); const v = d.toISOString().slice(0, 10); sel.innerHTML += '<option value="' + v + '">week containing ' + v + '</option>'; } sel.selectedIndex = 1; }
$('ovWeeks').innerHTML = (r.dueWeeks || []).length ? '<table><tr><th>Week of</th><th>Status</th><th>Total</th></tr>' + r.dueWeeks.map(w => '<tr><td>' + esc(w.week) + '</td><td>' + esc(OV_STATE[w.state] || w.state) + (w.heldWhy ? ' <span class="muted">(' + esc(w.heldWhy) + ')</span>' : '') + '</td><td class="mono">' + esc(w.totalPol || '0') + ' POL</td></tr>').join('') + '</table>' : '';
const st = r.status || {}; const t = r.totals || {};
$('ovOut').innerHTML = '<p>Week of ' + esc(r.week || '') + ': ' + (r.purchases || 0) + ' purchases, $' + Number(t.salesUsd || 0).toFixed(2) + ' sales. Override due: $' + Number(t.wouldPayUsd || 0).toFixed(2) + ' (' + Number(t.wouldPayPol || 0).toFixed(4) + ' POL) to ' + (r.recipients || []).length + ' members; company keeps $' + Number(t.companyKeepsUsd || 0).toFixed(2) + '. Payout status: <b>' + esc(OV_STATE[st.state] || st.state || '?') + '</b>' + (st.heldWhy ? ' (' + esc(st.heldWhy) + ')' : '') + '.</p>'
+ ((st.rows || []).length ? '<table><tr><th>Member</th><th>POL</th><th>USD</th><th>Status</th><th></th></tr>' + st.rows.map(x => '<tr><td>#' + x.memberId + '</td><td class="mono">' + esc(x.pol) + '</td><td class="mono">$' + Number(x.usd || 0).toFixed(2) + '</td><td>' + esc(x.state) + (x.note ? ' <span class="muted">' + esc(x.note) + '</span>' : '') + '</td><td>' + (x.tx ? '<a target="_blank" rel="noopener" href="' + esc(x.tx) + '">tx</a>' : '') + '</td></tr>').join('') + '</table>'
: (r.recipients || []).length ? '<table><tr><th>Member</th><th>POL</th><th>USD</th><th>Buys</th></tr>' + r.recipients.map(x => '<tr><td>#' + x.recipientId + '</td><td class="mono">' + Number(x.pol).toFixed(4) + '</td><td class="mono">$' + Number(x.usd).toFixed(2) + '</td><td>' + x.purchases + '</td></tr>').join('') + '</table>' : '');
}
if ($('ovShow')) $('ovShow').addEventListener('click', () => loadOverride($('ovWeek').value));
if ($('ovPay')) $('ovPay').addEventListener('click', async () => {
const wk = $('ovWeek').value;
if (!await IAP.confirmBox('This sends real POL from the payer wallet for every closed week up to the week containing ' + wk + ' that is not paid yet. Each member is paid once; anything already paid is skipped.', { title: 'Pay the override now?', ok: 'Pay now' })) return;
try { const r = await api('/api/admin/override/pay', { week: wk }); IAP.status('Override: ' + (r.results || []).map(x => x.week + ' ' + (x.state || x.held || (x.why || []).join(', '))).join(' · '), 'ok'); loadOverride(wk); } catch (e) { IAP.status(e.message, 'bad'); }
});
if ($('burnerRun')) $('burnerRun').addEventListener('click', async () => { try { const r = await api('/api/admin/burner/run', {}); IAP.status('Burner ran: ' + (r.burned || 0) + ' burned.', 'ok'); loadPnl(); } catch (e) { IAP.status(e.message, 'bad'); } });
async function loadAudit() {
if (!$('audTable')) return;
+1 -1
View File
@@ -93,7 +93,7 @@ window.IAP = (function () {
case 'AdminPaid': return 'platform fee settled: ' + pol(ev.amountWei);
case 'BuyerCounted': return '' + nm(ev.sponsorId) + ' now has ' + ev.newCount + ' qualifying buyer(s)';
case 'MemberActivated': return '' + nm(ev.id) + ' activated a payout wallet';
case 'AwardPaid': return 'award: ' + pol(ev.amountWei) + ' → ' + nm(ev.toId);
case 'AwardPaid': return ev.override ? 'Level 4 override' + (ev.overrideWeek ? ' (week of ' + ev.overrideWeek + ')' : '') + ': ' + pol(ev.amountWei) + ' → ' + nm(ev.toId) : 'award: ' + pol(ev.amountWei) + ' → ' + nm(ev.toId);
case 'CreditsConsumed': return '' + nm(ev.memberId) + ' ran ads: −' + ev.amount.toLocaleString() + ' credits';
case 'PriceCached': return 'oracle price refreshed';
case 'FallbackPriceUsed': return 'cached price bridged an oracle gap';
+5
View File
@@ -3,6 +3,11 @@
const $ = id => document.getElementById(id);
let c = {}; try { c = await (await fetch('/api/config')).json(); } catch (e) {}
const addr = String(c.contract || '');
// Level 4 override panel (2026-10-23): only when the site setting overrideMode is 'live' and overrideGoLive is set
if (String(c.overrideMode || '') === 'live' && Number(c.overrideGoLive) && $('ovPanel')) {
const d = new Date(Number(c.overrideGoLive)).toLocaleDateString('en-US', { timeZone: 'America/Chicago', month: 'long', day: 'numeric', year: 'numeric' });
document.querySelectorAll('[data-ov-start]').forEach(e => { e.textContent = d; }); $('ovPanel').hidden = false;
}
$('cAddr').textContent = addr || 'not deployed yet';
$('cChain').textContent = c.chainName || '';
const src = 'https://repo.sourcify.dev/contracts/full_match/' + (c.chainId || 137) + '/' + addr + '/';
+1 -1
View File
@@ -17,7 +17,7 @@
.map(([k, v, n], i) => '<div class="tile' + (i === 0 ? ' hi' : '') + '"><span class="k">' + k + '</span><span class="v">' + v + '</span><span class="muted mono" style="font-size:11px">' + n + '</span></div>').join('');
$('walletBox').innerHTML = addr ? '<div class="code" style="display:block">' + esc(addr) + '</div><div style="margin-top:8px">' + (on ? '<span class="ok"><span class="dot"></span>PAYOUTS ON · member #' + ME.memberId + '</span>' : '<span class="warn"><span class="dot"></span>WALLET LINKED · PAYOUTS OFF</span><div class="muted" style="margin-top:4px">Switch payouts on so the people you bring pay you from their first purchase.</div>') + '</div>' : '<span class="warn">No wallet linked yet.</span><div class="muted" style="margin-top:4px">Link one to be paid. Your email account keeps working either way.</div>';
const pays = E && Array.isArray(E.earnings) ? E.earnings : [];
$('payRows').innerHTML = pays.length ? pays.slice(0, 25).map(x => '<div class="rw"><span class="mono muted" style="font-size:12px">' + new Date((x.ts || 0) * (x.ts > 1e12 ? 1 : 1000)).toLocaleString() + '</span><span><b>' + esc(x.buyerName || x.fromName || (x.names && x.buyerId && x.names[x.buyerId] ? '@' + x.names[x.buyerId] : x.buyerId ? 'member #' + x.buyerId : x.type === 'AwardPaid' ? 'award' : 'member')) + '</b></span><span class="mono">' + (x.tier ? 'L' + x.tier + ' · ' + (x.tier === 1 ? '50%' : x.tier === 2 ? '20%' : '10%') : (x.type === 'AwardPaid' ? 'award' : '')) + '</span><span class="mono">' + (x.priceCents ? '$' + (x.priceCents / 100) : '') + '</span><span class="r num ok">+' + pol(x.amountWei || '0') + ' POL' + (U.usd > 0 ? '<br><span class="muted" style="font-size:11px">' + usd(x.amountWei) + '</span>' : '') + '</span>' + (x.tx ? '<a class="mono" style="font-size:11px" href="/tx/' + esc(x.tx) + '" target="_blank" rel="noopener">' + esc(String(x.tx).slice(0, 10)) + '…</a>' : '<span></span>') + '</div>').join('')
$('payRows').innerHTML = pays.length ? pays.slice(0, 25).map(x => '<div class="rw"><span class="mono muted" style="font-size:12px">' + new Date((x.ts || 0) * (x.ts > 1e12 ? 1 : 1000)).toLocaleString() + '</span><span><b>' + esc(x.buyerName || x.fromName || (x.names && x.buyerId && x.names[x.buyerId] ? '@' + x.names[x.buyerId] : x.buyerId ? 'member #' + x.buyerId : x.type === 'AwardPaid' ? (x.override ? 'Level 4 override' : 'award') : 'member')) + '</b></span><span class="mono">' + (x.tier ? 'L' + x.tier + ' · ' + (x.tier === 1 ? '50%' : x.tier === 2 ? '20%' : '10%') : (x.type === 'AwardPaid' ? (x.override ? 'L4 · 3%' : 'award') : '')) + '</span><span class="mono">' + (x.priceCents ? '$' + (x.priceCents / 100) : '') + '</span><span class="r num ok">+' + pol(x.amountWei || '0') + ' POL' + (U.usd > 0 ? '<br><span class="muted" style="font-size:11px">' + usd(x.amountWei) + '</span>' : '') + '</span>' + (x.tx ? '<a class="mono" style="font-size:11px" href="/tx/' + esc(x.tx) + '" target="_blank" rel="noopener">' + esc(String(x.tx).slice(0, 10)) + '…</a>' : '<span></span>') + '</div>').join('')
: '<div class="rw"><span class="muted">No payouts yet. They appear here the moment someone in your line buys.</span></div>';
$('payFoot').textContent = 'every line is a Polygon transaction · nothing is held by the site' + (U.usd > 0 ? ' · 1 POL ≈ $' + U.usd.toFixed(4) + ' at today’s price (updated ' + Math.max(0, Math.round((Date.now() - U.at) / 60000)) + ' min ago); dollar amounts are today’s value, not the value on the payout day' : '');
const rows = Array.isArray(POS) ? POS : (POS && (POS.positions || POS.list)) || [];
+12 -1
View File
@@ -104,6 +104,17 @@
</div>
</div>
<div class="panel" id="ovPanel" hidden><!-- Level 4 override: shown only when overrideMode is live (contract.js) -->
<div class="ph"><h2>Level 4 override</h2><span class="meta">company paid · weekly · not in the contract</span></div>
<div class="pb" style="padding-top:6px">
<div class="rule"><b>What</b><span>On top of the three levels above, the company pays 3% of every package bought four levels below you. It goes to the 4th sponsor up from the buyer, as long as that member has 5 or more qualifying buyers (referrals who bought a package of $25 or more), the same bar that opens level 3.</span></div>
<div class="rule"><b>Hunts upward</b><span>If the 4th sponsor up is not qualified yet, the override moves up the line to the next member who is, up to 25 steps. One override per purchase, to one person. If it reaches the company account first, or nobody qualifies, the company keeps it.</span></div>
<div class="rule"><b>Paid weekly</b><span>Every Monday after 9 AM Central, in POL, from a company wallet through this contract's public award function, for the Monday to Sunday week before. Every payment has its own Polygon link and shows on your Wallet screen as "Level 4 override". Weekly totals under 0.01 POL carry to the next week.</span></div>
<div class="rule"><b>Start date</b><span>Purchases from <span data-ov-start>the start date</span> on. Earlier purchases are not paid.</span></div>
<div class="rule"><b>Funding</b><span>It comes out of the platform's 20% share. The split the contract enforces does not change for anyone.</span></div>
</div>
</div>
<div class="panel">
<div class="ph"><h2>What this is and is not</h2><span class="meta">read before you buy</span></div>
<div class="pb grid3" style="font-size:14px;color:var(--ink-2)">
@@ -136,6 +147,6 @@
<span class="mono" style="font-size:11px">Advertising services with a performance referral program. Not an investment. Crypto transactions are irreversible.</span>
</div>
</footer>
<script src="/assets/contract.js?v=20261007a"></script>
<script src="/assets/contract.js?v=20261023ov"></script>
</body>
</html>
+1 -1
View File
@@ -80,7 +80,7 @@
</div>
</div>
</div>
<script src="/assets/common.js?v=20261018p25"></script>
<script src="/assets/common.js?v=20261023ov"></script>
<script src="/assets/wallet.js?v=20261021a"></script>
<script src="/assets/cr-shell.js?v=20261023a"></script>
<script src="/assets/credits-screen.js?v=20261019pos"></script>
+1 -1
View File
@@ -68,6 +68,6 @@
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees.</div>
</footer>
</div>
<script src="/assets/common.js?v=20261018p25"></script>
<script src="/assets/common.js?v=20261023ov"></script>
</body>
</html>
+1 -1
View File
@@ -105,7 +105,7 @@ body.squeeze .card{position:sticky;top:16px}
<span class="mono" style="font-size:11px">a Crypto Team Build Network property</span>
</div>
</footer>
<script src="/assets/common.js?v=20261018p25"></script>
<script src="/assets/common.js?v=20261023ov"></script>
<script src="/assets/join.js?v=20261009b"></script>
</body>
</html>
+1 -1
View File
@@ -104,7 +104,7 @@
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees.</div>
</footer>
</div>
<script src="/assets/common.js?v=20261018p25"></script>
<script src="/assets/common.js?v=20261023ov"></script>
<script src="/assets/launch.js?v=20260915b"></script>
</body>
</html>
+1 -1
View File
@@ -64,7 +64,7 @@
<span class="mono" style="font-size:11px">a Crypto Team Build Network property</span>
</div>
</footer>
<script src="/assets/common.js?v=20261018p25"></script>
<script src="/assets/common.js?v=20261023ov"></script>
<script src="/assets/ledger.js?v=20261007a"></script>
</body>
</html>
+1 -1
View File
@@ -1007,7 +1007,7 @@
</div>
</div>
</div>
<script src="/assets/common.js?v=20261018p25"></script>
<script src="/assets/common.js?v=20261023ov"></script>
<script src="/assets/cr-shell.js?v=20261023a"></script>
<script src="/assets/tools.js?v=20261011a"></script>
<script src="/assets/wallet.js?v=20261021a"></script>
+1 -1
View File
@@ -130,7 +130,7 @@
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees. Crypto transactions are irreversible. Never spend what you cannot afford to lose.</div>
</footer>
</div>
<script src="/assets/common.js?v=20261018p25"></script>
<script src="/assets/common.js?v=20261023ov"></script>
<script src="/assets/partners.js?v=20261010a"></script>
</body>
</html>
+1 -1
View File
@@ -192,7 +192,7 @@
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees. Crypto transactions are irreversible. Never spend what you cannot afford.</div>
</footer>
</div>
<script src="/assets/common.js?v=20261018p25"></script>
<script src="/assets/common.js?v=20261023ov"></script>
<script src="/assets/plays.js?v=20260910b"></script>
</body>
</html>
+1 -1
View File
@@ -66,7 +66,7 @@
<span class="mono" style="font-size:11px">a Crypto Team Build Network property</span>
</div>
</footer>
<script src="/assets/common.js?v=20261018p25"></script>
<script src="/assets/common.js?v=20261023ov"></script>
<script src="/assets/support.js?v=20261016a"></script>
</body>
</html>
+1 -1
View File
@@ -34,7 +34,7 @@
<p><a href="/ledger">← Back to the live ledger</a> · <a href="/contract">Read the contract review</a></p>
</div>
</section>
<script src="/assets/common.js?v=20261018p25"></script>
<script src="/assets/common.js?v=20261023ov"></script>
<script src="/assets/tx.js?v=20260906m"></script>
</body>
</html>
+1 -1
View File
@@ -47,7 +47,7 @@
</div>
</div>
</section>
<script src="/assets/common.js?v=20261018p25"></script>
<script src="/assets/common.js?v=20261023ov"></script>
<script src="/assets/wall.js?v=20261008a"></script>
</body>
</html>
+1 -1
View File
@@ -32,6 +32,6 @@
</div>
</div>
<script src="/assets/cr-shell.js?v=20261023a"></script>
<script src="/assets/wallet-screen.js?v=20261022usd"></script>
<script src="/assets/wallet-screen.js?v=20261023ov"></script>
</body>
</html>
+1 -1
View File
@@ -121,7 +121,7 @@
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees. Crypto transactions are irreversible. Never share your recovery phrase.</div>
</footer>
</div>
<script src="/assets/common.js?v=20261018p25"></script>
<script src="/assets/common.js?v=20261023ov"></script>
<script src="/assets/wallets.js?v=20261018p25"></script>
</body>
</html>