Holding tank activation hold (Marty approved 2026-10-27, "hold them for no longer than 24 hours"): a tank member is never bound under the fallback #1
- Align first: a tank member whose email or wallet already has a sponsor on LinkSpin (the inbound registry rows) is placed under that sponsor when they have a real account here, never a sponsor they were released/rescued from, never a loop (recorded in tank-ready.json, shown in Admin tank)
- Hold: /api/me and /api/sponsor answer tankHold {since, until} instead of the fallback sponsor; Wallet tab hides Activate payouts and shows "You're being matched with a sponsor..." with time left, Getting started has no activate button, buy flows (my + home) refuse on tankHold. The 24-hour clock starts when the member is first seen with a wallet linked (already-linked members start at deploy)
- Surface: Ready to activate badge + hours left, ready members on top (My line tank, Admin tank, Overview notice count); one Telegram line per newly ready member (digest when more than 3, e.g. the first tick after deploy)
- Safety net (readyTick every 15 min + hourly sweep): unadopted 24 h after readyAt -> next eligible adopter in rotation (own $20+ buy, fewer than 2 open, signed in within 7 days, not suspended/flagged, not company, not a no-payout chain, not in their own downline; least recently auto-assigned first, ties by earliest qualification) through adopt() with "auto-assigned after 24 hours in the tank", chat + email to both, Telegram pickup "(auto-assigned)". Nobody eligible: keep holding, one admin alert
- tank.eligibility is now exported (the Overview tank notice was silently failing on it)
- Chatbot: tank-hold canned answer, holding-tank answer + system prompt updated, KNOWLEDGE_DATE 2026-10-27
- qa/tank-hold.mjs (mocked clock unit + local copy e2e), wired into run.sh member and run.sh tankhold; cache tags bumped
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -634,7 +634,11 @@ async function boot() {
|
||||
sponsorAccount: em => accounts.byEmail(em),
|
||||
wouldCycle: async (email, sp) => { let cur = sp; const seen = new Set(); for (let i = 0; cur && i < 60; i++) { if (cur.email === email || seen.has(cur.email)) return true; seen.add(cur.email); cur = await accounts.sponsorOf(cur.email); } return false; },
|
||||
activationOf: a => a.address ? activationByAddress().get(String(a.address).toLowerCase()) || null : null });
|
||||
tank.init({ dataDir: DATA_DIR, chain, accounts, messages, mailer, ads, site: 'https://instantadpay.com', follow, store: followStore });
|
||||
tank.init({ dataDir: DATA_DIR, chain, accounts, messages, mailer, ads, site: 'https://instantadpay.com', follow, store: followStore,
|
||||
// activation hold + 24-hour safety net (2026-10-27): a tank member is never bound under the fallback position
|
||||
hooks: { network: (email, address) => lsinbound.networkSponsor(email, address), isSuspended: em => fraud.isSuspended(em), excluded: em => fraud.excluded(em),
|
||||
payoutBlocked: id => payoutChainBlocked(id, 2), companyId: () => Number(siteConfig().defaultSponsorId) || 1,
|
||||
assigned: r => { tankPickupPost(r.adopterName, r.adopteeName, true); }, adminAlert: text => tankAdminAlert(text) } });
|
||||
// LinkSpin registry sync (2026-10-08): every account change is pushed to LinkSpin within seconds; a 2-minute reconcile catches the rest
|
||||
lssync.init({ dataDir: DATA_DIR, accounts, follow: followStore, tank: () => tank }); accounts.onChange(email => lssync.touch(email));
|
||||
lsinbound.init({ dataDir: DATA_DIR, accounts, lssync, follow, store: followStore });
|
||||
@@ -712,6 +716,8 @@ async function boot() {
|
||||
setInterval(() => leaderboard.rolloverTick().catch(e => console.error('leaderboard rollover', e.message)), 60 * 60 * 1000);
|
||||
console.log('blog syndication:', syndicate.enabled() ? 'on (X + Instagram via Blotato)' : 'off (no blotato.key)');
|
||||
setInterval(() => tankNotifyTick().catch(e => console.error('tank notify', e.message)), 15 * 60 * 1000); // new tank arrivals -> Telegram
|
||||
setTimeout(() => tankReadyTick().catch(e => console.error('tank ready', e.message)), 2 * 60 * 1000); // after the LinkSpin inbound state is loaded
|
||||
setInterval(() => tankReadyTick().catch(e => console.error('tank ready', e.message)), 15 * 60 * 1000); // align / 24-hour hold / safety net
|
||||
geo.init({ dataDir: DATA_DIR }).catch(e => console.error('geo init', e.message));
|
||||
setInterval(() => geo.refresh().catch(e => console.error('geo refresh', e.message)), 24 * 3600 * 1000); // monthly file, checked daily
|
||||
setInterval(() => tank.sweep().catch(e => console.error('tank sweep', e.message)), 60 * 60 * 1000); // adoptions past their 7-day window
|
||||
@@ -1465,6 +1471,43 @@ async function tankNotifyTick() {
|
||||
+ '\nAdopt from My line \u203a Holding tank: <a href="https://instantadpay.com/my#line">instantadpay.com/my</a>';
|
||||
await telegramSend(sc.telegramEchoChatId, text, sc.telegramEchoTopicId);
|
||||
}
|
||||
// a holding-tank pickup: the live feed + one line in the shared payments topic (manual adoptions since 2026-09-12;
|
||||
// the 24-hour safety net says "(auto-assigned)", 2026-10-27)
|
||||
function tankPickupPost(adopterName, adopteeName, auto) {
|
||||
pushFeed({ type: 'Adopted', sponsor: adopterName, member: adopteeName, ts: Date.now() });
|
||||
try {
|
||||
const sc = siteConfig();
|
||||
const clean = t => String(t || '').replace(/[<>&]/g, '');
|
||||
if (sc.telegramBotToken && sc.telegramEchoChatId)
|
||||
telegramSend(sc.telegramEchoChatId, '\u{1F91D} <b>InstantAdPay</b> \u00b7 <b>' + clean(adopterName) + '</b> picked up <b>' + clean(adopteeName) + '</b> from the holding tank and is now their sponsor' + (auto ? ' (auto-assigned)' : ''), sc.telegramEchoTopicId).catch(() => {});
|
||||
} catch (e) {}
|
||||
}
|
||||
// admin-only channels (never a member-visible topic: it names an email), the same order as the video-sweep alerts
|
||||
async function tankAdminAlert(text) {
|
||||
const sc = siteConfig(); const hermes = String(process.env.HERMES_BOT_TOKEN || '').trim();
|
||||
const html = String(text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||||
if (hermes && sc.telegramAdminChatId) return tgSendAs(hermes, sc.telegramAdminChatId, html);
|
||||
if (sc.telegramBotToken && sc.telegramAdminChatId) return telegramSend(sc.telegramAdminChatId, html);
|
||||
if (ADMIN_EMAIL && mailer.hasKey()) return mailer.send(ADMIN_EMAIL, 'InstantAdPay: holding tank needs an adopter', text);
|
||||
console.log('tank: no admin channel configured, alert not sent:', text);
|
||||
}
|
||||
// holding tank every 15 min (2026-10-27): align members the network already knows, start the 24-hour clock for anyone
|
||||
// who linked a wallet, run the safety net, and tell the shared payments topic once per member who became ready
|
||||
async function tankReadyTick() {
|
||||
const r = await tank.readyTick();
|
||||
if (r.aligned || r.assigned.length || r.held || r.fresh.length) console.log('tank ready tick', JSON.stringify({ fresh: r.fresh.length, aligned: r.aligned, assigned: r.assigned.length, held: r.held }));
|
||||
const sc = siteConfig();
|
||||
if (!r.fresh.length || !sc.telegramBotToken || !sc.telegramEchoChatId) return r;
|
||||
const clean = t => String(t || '').replace(/[<>&]/g, '');
|
||||
const link = 'https://instantadpay.com/my#line';
|
||||
if (r.fresh.length <= 3) {
|
||||
for (const w of r.fresh) await telegramSend(sc.telegramEchoChatId, '\u{1F7E2} ' + (w.username ? '@' + clean(w.username) : 'A new member') + ' linked a wallet and is ready to switch on payouts. Adopt them from the holding tank in the next 24 hours: ' + link, sc.telegramEchoTopicId).catch(() => {});
|
||||
} else { // first run after deploy (the members already linked) or a busy quarter hour: one digest, not a wall of posts
|
||||
const named = r.fresh.filter(w => w.username).map(w => '@' + clean(w.username));
|
||||
await telegramSend(sc.telegramEchoChatId, '\u{1F7E2} ' + r.fresh.length + ' members linked a wallet and are ready to switch on payouts' + (named.length ? ': ' + named.slice(0, 12).join(', ') + (named.length > 12 ? ' and ' + (named.length - 12) + ' more' : '') : '') + '. Adopt them from the holding tank in the next 24 hours: ' + link, sc.telegramEchoTopicId).catch(() => {});
|
||||
}
|
||||
return r;
|
||||
}
|
||||
// one sendMessage call; never throws, never logs the token
|
||||
async function telegramSend(chatId, text, threadId) {
|
||||
const sc = siteConfig();
|
||||
@@ -2270,9 +2313,20 @@ const server = http.createServer(async (req, res) => {
|
||||
}
|
||||
} else if (acct && acct.sponsorRef && !sponsorId && spd.reason !== 'none') { sponsorBlocked = spd.reason; if (u.searchParams.get('intent') === 'buy') sponsorBlockedAlert(acct.email, Object.assign({ tok }, spd)); }
|
||||
if (sponsorId && await payoutChainBlocked(sponsorId, 2)) { console.log('sponsor routed away from no-payout chain', sponsorId); sponsorId = 0; }
|
||||
// holding tank (2026-10-27): a signed-in member with no sponsor and no member number is never bound under the
|
||||
// fallback. Network sponsor first (LinkSpin), else the hold (the buy and activate buttons refuse on tankHold).
|
||||
let tankHold = null;
|
||||
if (!sponsorId && acct && !acct.sponsorRef && !acct.memberId) {
|
||||
try {
|
||||
const h = await tank.holdFor(acct);
|
||||
if (h && h.aligned) { const a2 = await accounts.byEmail(acct.email); const sp2 = await resolveSponsorDetailed(a2 && a2.sponsorRef); if (sp2.id && !(await payoutChainBlocked(sp2.id, 2))) sponsorId = sp2.id; else tankHold = { since: null, until: null }; } // aligned: their sponsor's position (or held while it is not usable yet)
|
||||
else if (h && h.hold) tankHold = h.hold;
|
||||
} catch (e) { tankHold = { since: null, until: null }; }
|
||||
if (tankHold) sponsorBlocked = 'tankHold';
|
||||
}
|
||||
// orphan fallback: an unresolvable/absent sponsor (dead link, no link) lands
|
||||
// the new member under the configured catch position (#1) instead of root
|
||||
if (!sponsorId && (!acct || acct.memberId !== (Number(siteConfig().defaultSponsorId) || 1))) sponsorId = Number(siteConfig().defaultSponsorId) || 1;
|
||||
if (!sponsorId && !tankHold && (!acct || acct.memberId !== (Number(siteConfig().defaultSponsorId) || 1))) sponsorId = Number(siteConfig().defaultSponsorId) || 1;
|
||||
let name = null, avatarUrl = null, own = false;
|
||||
// the join page names the owner of the LINK it was opened with (?ref=token), not the visitor's own
|
||||
// sponsor: a member previewing their own invite page was seeing their upline's name (Jim, 2026-09-13)
|
||||
@@ -2295,7 +2349,7 @@ const server = http.createServer(async (req, res) => {
|
||||
let invited = !!showTok;
|
||||
if (!invited && tok) { try { invited = !(await fraud.hasAccountOnDevice(req)); } catch (e) { invited = true; } }
|
||||
if (acct) invited = false; // already a member: they are not joining anybody's line
|
||||
return json(res, 200, { ref: tok, sponsorId, sponsorBlocked, sponsorRouted, sponsorName: spd.name || null, invited, name, avatarUrl, own, bio: typeof bio === 'undefined' ? null : bio, cobrand: typeof cobrand === 'undefined' ? false : cobrand });
|
||||
return json(res, 200, { ref: tok, sponsorId, sponsorBlocked, sponsorRouted, tankHold, sponsorName: spd.name || null, invited, name, avatarUrl, own, bio: typeof bio === 'undefined' ? null : bio, cobrand: typeof cobrand === 'undefined' ? false : cobrand });
|
||||
}
|
||||
if (p === '/api/stats' && req.method === 'GET') {
|
||||
let members = 0; try { members = await chain.memberCount(); } catch (e) {}
|
||||
@@ -2669,7 +2723,9 @@ const server = http.createServer(async (req, res) => {
|
||||
const s = await auth.fromRequest(req);
|
||||
if (!s) return json(res, 200, { signedIn: false });
|
||||
const memberId = await auth.refreshMemberId(s);
|
||||
const acct = (s.email && await accounts.byEmail(s.email)) || (s.address && await accounts.byAddress(s.address)) || null;
|
||||
let acct = (s.email && await accounts.byEmail(s.email)) || (s.address && await accounts.byAddress(s.address)) || null;
|
||||
// holding tank (2026-10-27): someone the network already knows is placed under that sponsor first (tank.js alignToNetwork)
|
||||
if (acct && !acct.sponsorRef && !acct.memberId && !memberId) { try { if (await tank.alignToNetwork(acct)) acct = (await accounts.byEmail(acct.email)) || acct; } catch (e) {} }
|
||||
const spdMe = await resolveSponsorDetailed((acct && acct.sponsorRef) || parseCookies(req)['iap.sponsor']); let sponsorId = spdMe.id;
|
||||
let sponsorBlocked = (acct && acct.sponsorRef && !sponsorId && spdMe.reason !== 'none') ? spdMe.reason : null;
|
||||
let sponsorRouted = null;
|
||||
@@ -2680,12 +2736,16 @@ const server = http.createServer(async (req, res) => {
|
||||
}
|
||||
if (sponsorId && await payoutChainBlocked(sponsorId, 2)) sponsorId = 0;
|
||||
const _defSpon = Number(siteConfig().defaultSponsorId) || 1;
|
||||
if (!sponsorId && memberId !== _defSpon) sponsorId = _defSpon; // orphan fallback → #1 (never self-sponsor)
|
||||
// a holding-tank member is never bound under the fallback: held for an adopter (24 h at most, then the rotation)
|
||||
let tankHold = null;
|
||||
if (!sponsorId && !memberId && acct && !acct.sponsorRef && !acct.memberId) { try { const h = await tank.holdFor(acct); if (h && h.hold) tankHold = h.hold; } catch (e) { tankHold = { since: null, until: null }; } }
|
||||
if (tankHold) sponsorBlocked = 'tankHold';
|
||||
else if (!sponsorId && memberId !== _defSpon) sponsorId = _defSpon; // orphan fallback → #1 (never self-sponsor)
|
||||
if (memberId && acct && acct.memberId !== memberId) accounts.setMemberId(acct.email, memberId).catch(() => {});
|
||||
const out = { signedIn: true, gkShop: !!parseCookies(req)['iap.gkshop'], sdShop: !!parseCookies(req)['iap.sdshop'], pwMint: !!parseCookies(req)['iap.pwmint'], returnTo: ['polhunter', 'driprunner', 'passivedrip', 'gemkingdom', 'gkshop', 'spookydoors', 'sdshop', 'pwmint', 'polybreak', 'shardsofvalor'].includes(parseCookies(req)['iap.return']) ? parseCookies(req)['iap.return'] : null, sponsorBlocked, sponsorRouted, sponsorName: spdMe.name || null, email: s.email || (acct && acct.email) || null,
|
||||
address: s.address || (acct && acct.address) || null, memberId,
|
||||
username: (acct && acct.username) || null,
|
||||
refCode: (acct && acct.code) || null, sponsorId,
|
||||
refCode: (acct && acct.code) || null, sponsorId, tankHold,
|
||||
// profile + line-banner fields so the Profile pane repopulates on reload (were being saved but not returned)
|
||||
avatarUrl: (acct && acct.avatarUrl) || null, bio: (acct && acct.bio) || null,
|
||||
socials: (acct && acct.socials) || null,
|
||||
@@ -2713,7 +2773,7 @@ const server = http.createServer(async (req, res) => {
|
||||
try {
|
||||
if (!tankWaitCache || Date.now() - tankWaitCache.ts > 60000) tankWaitCache = { ts: Date.now(), list: await tank.waiting() };
|
||||
const tw = tankWaitCache.list;
|
||||
tankWaiting = { count: tw.length, names: tw.slice(0, 6).map(w => w.name), eligible: !!(await tank.eligibility(s.email)).ok };
|
||||
tankWaiting = { count: tw.length, names: tw.slice(0, 6).map(w => w.name), eligible: !!(await tank.eligibility(s.email)).ok, ready: tw.filter(w => w.ready).length };
|
||||
} catch (e) {}
|
||||
const sc0 = siteConfig();
|
||||
const out = { memberId, tankWaiting, email: s.email || (acct && acct.email) || null,
|
||||
@@ -3172,13 +3232,7 @@ const server = http.createServer(async (req, res) => {
|
||||
if (fraud.excluded(s.email)) return json(res, 403, { error: 'Adoptions are not available on this account. Contact support at instantadpay.com/support.' });
|
||||
const r = await tank.adopt(s.email, b.who, b.note);
|
||||
if (r.ok) { // tell the payments topic who picked whom up (Marty, 2026-09-12)
|
||||
pushFeed({ type: 'Adopted', sponsor: r.adopterName, member: r.adopteeName, ts: Date.now() });
|
||||
try {
|
||||
const sc = siteConfig();
|
||||
const clean = t => String(t || '').replace(/[<>&]/g, '');
|
||||
if (sc.telegramBotToken && sc.telegramEchoChatId)
|
||||
telegramSend(sc.telegramEchoChatId, '\u{1F91D} <b>InstantAdPay</b> \u00b7 <b>' + clean(r.adopterName) + '</b> picked up <b>' + clean(r.adopteeName) + '</b> from the holding tank and is now their sponsor', sc.telegramEchoTopicId).catch(() => {});
|
||||
} catch (e) {}
|
||||
tankPickupPost(r.adopterName, r.adopteeName, false);
|
||||
}
|
||||
return json(res, r.error ? 400 : 200, r);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user