// All runtime config comes from env (Coolify sets these). Read once; the house-ad list can also be // overridden by DATA_DIR/house.json so it changes without a redeploy. const fs = require('fs'); const path = require('path'); const NETS = { 80002: { name: 'Polygon Amoy (testnet rehearsal)', explorer: 'https://amoy.polygonscan.com', rpcs: ['https://polygon-amoy-bor-rpc.publicnode.com', 'https://polygon-amoy.drpc.org'] }, // drpc first: publicnode refuses some log/archive queries (kept as fallback, InstantAdPay-style rotation) 137: { name: 'Polygon', explorer: 'https://polygonscan.com', rpcs: ['https://polygon.drpc.org', 'https://polygon-bor-rpc.publicnode.com', 'https://polygon-rpc.com'] }, 31337: { name: 'Local anvil', explorer: '', rpcs: ['http://127.0.0.1:8545'] } }; // Production default: the BannerLine contract on Polygon mainnet (deployed 2026-11-13, owner = Marty's Tangem, // keeper 0xcAF8EF6eFDFC9597780Db5a1F6b2efE525868e37). Other chains (80002 Amoy, 31337 anvil) need CONTRACT_ADDRESS set. const MAINNET = { contract: '0x6c77fc0664f58cf17e81966160fc80005a110f9b', deployBlock: 97245075 }; let cfg = null; function get() { if (cfg) return cfg; const e = process.env; const chainId = Number(e.CHAIN_ID || 137); const main = chainId === 137; const net = NETS[chainId] || NETS[137]; const list = s => String(s || '').split(',').map(x => x.trim()).filter(Boolean); cfg = { port: Number(e.PORT || 3000), isProd: e.NODE_ENV === 'production', site: e.SITE_HOST || 'downlinebanners.com', dataDir: e.DATA_DIR || path.join(__dirname, 'data'), contract: (e.CONTRACT_ADDRESS || (main ? MAINNET.contract : '')).trim(), chainId, chainName: e.CHAIN_NAME || net.name, explorer: e.EXPLORER_URL !== undefined ? e.EXPLORER_URL : net.explorer, rpcs: list(e.RPC_URLS).length ? list(e.RPC_URLS) : net.rpcs, publicRpc: e.PUBLIC_RPC || (list(e.RPC_URLS)[0] || net.rpcs[0]), // handed to the wallet for add/switch chain deployBlock: Number(e.START_BLOCK || e.DEPLOY_BLOCK || (main && String(e.CONTRACT_ADDRESS || MAINNET.contract).trim().toLowerCase() === MAINNET.contract ? MAINNET.deployBlock : 0)), confirmations: Number(e.CONFIRMATIONS !== undefined ? e.CONFIRMATIONS : (chainId === 31337 ? 0 : 3)), pollMs: Number(e.POLL_MS || 20000), priceFeed: (e.PRICE_FEED || '').trim(), allowStaleFeed: e.ALLOW_STALE_FEED === '1', walletConnectProjectId: (e.WALLETCONNECT_PROJECT_ID || '').trim(), // board + gate viewsOwed: 300, spotDays: 30, boardSlots: Number(e.BOARD_SLOTS || 12), gateVisitSeconds: 9, gateBoardSeconds: 10, // keeper (fund buys). KEEPER_KEY is never stored in cfg: keeper.js reads it from env at signing time only. keeperEnabled: e.KEEPER_ENABLED === '1', keeperStallHours: Number(e.KEEPER_STALL_HOURS || 4), keeperMaxPerDay: Number(e.KEEPER_MAX_PER_DAY || 12), keeperEveryMs: Number(e.KEEPER_EVERY_MIN || 15) * 60000, iapBase: String(e.IAP_URL || 'https://instantadpay.com').replace(/\/+$/, ''), lsBase: String(e.LS_URL || 'https://linkspin.app').replace(/\/+$/, ''), // network usernames: ?u= -> {address, username}, ?a= -> the same (InstantAdPay today, the network hub later) networkLookupUrl: (e.NETWORK_LOOKUP_URL || String(e.IAP_URL || 'https://instantadpay.com').replace(/\/+$/, '') + '/api/network/member').trim() }; return cfg; } // House ads fill empty board slots. Order of fill: member LinkSpin Banner Spins (hook in board.js), then these. // Image paths avoid ad-blocker patterns (no size tokens, no /banners/ folder). const HOUSE_DEFAULT = [ { key: 'iap', title: 'InstantAdPay', img: '/art/house-iap.svg', link: 'https://instantadpay.com/', note: 'Ad credits buy advertising, not income.' }, { key: 'linkspin', title: 'LinkSpin', img: '/art/house-linkspin.svg', link: 'https://linkspin.app/' }, { key: 'games', title: 'Network games', img: '/art/house-games.svg', link: 'https://enjoybestgames.com/' }, { key: 'self', title: 'Downline Banners', img: '/art/house-line.svg', link: '/join' } ]; function house() { try { const h = JSON.parse(fs.readFileSync(path.join(get().dataDir, 'house.json'), 'utf8')); if (Array.isArray(h) && h.length) return h; } catch (e) {} return HOUSE_DEFAULT; } module.exports = { get, house, reset: () => { cfg = null; } };