aee1ccc36a
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>
65 lines
5.4 KiB
JavaScript
65 lines
5.4 KiB
JavaScript
// All runtime config comes from env (Coolify sets these). Read once.
|
|
// 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;
|
|
function get() {
|
|
if (cfg) return cfg;
|
|
const e = process.env;
|
|
const list = (v, d) => String(v == null || v === '' ? d : v).split(',').map(x => x.trim()).filter(Boolean);
|
|
const num = (v, d, min, max) => { const n = Number(v); return Number.isFinite(n) && v !== '' && v != null ? Math.min(max, Math.max(min, Math.round(n))) : d; };
|
|
cfg = {
|
|
port: Number(e.PORT || 3000),
|
|
isProd: e.NODE_ENV === 'production',
|
|
site: e.SITE_HOST || 'viralbannerblitz.com',
|
|
siteName: 'Viral Banner Blitz',
|
|
dataDir: e.DATA_DIR || path.join(__dirname, 'data'),
|
|
chainId: Number(e.CHAIN_ID || 137), // only used in the wallet sign-in message + picker
|
|
chainName: e.CHAIN_NAME || 'Polygon',
|
|
publicRpc: e.PUBLIC_RPC || 'https://polygon-bor-rpc.publicnode.com',
|
|
walletConnectProjectId: (e.WALLETCONNECT_PROJECT_ID || '').trim(),
|
|
// the loop
|
|
loopSize: num(e.LOOP_SIZE, 50, 5, 500), // banners on the splash at once
|
|
perShift: num(e.VISITORS_PER_SHIFT, 10, 1, 1000), // verified unique visitors per one-place shift
|
|
viewsPerCycle: num(e.VIEWS_PER_CYCLE, 150, 0, 100000), // network ad views recorded per completed cycle (not credited in v1)
|
|
// verified visitors
|
|
visitSeconds: num(e.VISIT_SECONDS, 6, 2, 60), // the page must be visible this long before the visit counts
|
|
visitWindowHours: 24, // one count per visitor key per 24 h
|
|
perIpDay: num(e.VISITS_PER_IP_DAY, 3, 1, 100), // distinct user agents counted per IP per 24 h (shared connections, UA rotation)
|
|
// members
|
|
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), 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),
|
|
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
|
|
shopStartBlock: num(e.SHOP_START_BLOCK, 0, 0, 1e12), // the deploy block (first scan starts here)
|
|
shopConfirmations: num(e.SHOP_CONFIRMATIONS, 10, 0, 1000), // credit only this many blocks behind the head
|
|
shopPollMs: num(e.SHOP_POLL_MS, 30000, 200, 3600000),
|
|
voucherSeconds: num(e.VOUCHER_SECONDS, 1800, 60, 86400), // a sponsor voucher is good for 30 minutes
|
|
linkProbe: e.LINK_PROBE !== '0', // check the target link answers and allows frames (off in the local smoke test)
|
|
iapBase: String(e.IAP_URL || 'https://instantadpay.com').replace(/\/+$/, ''),
|
|
lsBase: String(e.LS_URL || 'https://linkspin.app').replace(/\/+$/, ''),
|
|
// network usernames: ?u=<username> / ?a=<wallet> -> {address, username}. '' turns the lookup off (local prototype).
|
|
networkLookupUrl: e.NETWORK_LOOKUP_URL !== undefined ? String(e.NETWORK_LOOKUP_URL).trim()
|
|
: String(e.IAP_URL || 'https://instantadpay.com').replace(/\/+$/, '') + '/api/network/member'
|
|
};
|
|
return cfg;
|
|
}
|
|
|
|
module.exports = { get, reset: () => { cfg = null; } };
|