// 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= / ?a= -> {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; } };