VBB purchases live + weekly prize payouts (Marty 2026-11-14: "why does it say 'coming soon' on all the stuff in it? Shouldn't it all be live already?")

Buying (VBBShop 0x36F6...07D7): Packages page has live Buy buttons for the 10 and 40 credit packs (USD price + live POL from quoteWei, SafePal or any other crypto wallet, one-time, never a subscription, where the payment goes); My Banners has "Add the banner look ($2)" on each waiting or in-loop banner (SKU 3, ref = banner id) and a 40-character teaser editor once it has the look. POST /api/my/order builds the member's buy() call on the server (fresh keeper voucher when the hub knows their sponsor, else no sponsor); the page checks the connected wallet is the member's VBB account (explains how to switch if not), checks the balance, sends with Polygon's fee floor (/api/gas), waits on /api/tx, nudges the watcher (/api/my/paid) and polls until the credits or the look arrive. Public: /api/quote, /api/gas, /api/tx/<hash>; /api/config has shop {live, contract} + explorer. The banner look on the loop: double border + star, hover teaser (always shown on touch screens; default = the link's site). Only Tokens still says coming soon. wallet.js gains sendTx/waitTx/balance (DLB flow).

Weekly prize payouts (prize.js): each Central-time week's pot = 10% of its VBBShop sales (usdCents of Purchase events by block time), $20 floor (company top-up shown to admin), $50 cap internal, half per board, 50/30/20. Every Monday the app prepares last week's plan (winners, wallets, USD; POL quoted live from the Chainlink feed the contract uses). /admin "Approve and pay" (two clicks): refuses unless PRIZE_KEY is the contract's prizeWallet(), the feed is fresh and the wallet holds the POL + gas (says how much more to send); then once per week (docstore.claim in MySQL + plan status), consecutive nonces, each hash saved as sent, stops at the first unclear send (never auto-retried), receipts watched. Ties: earlier to reach the count wins (leaderboards use the same rule). A winner that cannot be paid (the prize or company wallet) is skipped and the rest move up; an unfilled place stays in the prize wallet. /leaders shows past winners with transaction links. Posts nothing anywhere. Compose passes PRIZE_KEY.

Tests: smoke 192/192 (stand-in chain answers quoteWei + receipts: quote, order calldata + voucher, look purchase, teaser, prizes API, UI Buy buttons). New qa/chain.mjs on a local anvil with the real VBBShop + mock feed: buy -> Purchase -> credits, voucher binds sponsor, 30/10/60 split, overpay refunded, banner look; prize prepare -> short refusal -> pay 6 transfers exact POL -> paid once: 29/29. common.js?v=3, vbb.css?v=4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-14 09:47:58 -06:00
parent a6a9b3cace
commit aee1ccc36a
27 changed files with 866 additions and 79 deletions
+10 -6
View File
@@ -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