From ab65439ad4a488c0f202307a7b09f1864e3b58e6 Mon Sep 17 00:00:00 2001 From: martbost Date: Thu, 8 Oct 2026 06:41:54 -0500 Subject: [PATCH] Sponsor fallback never names a position the contract does not have yet: on a fresh contract the first member joins with sponsor 0 and becomes #1 (Marty's activate(1) reverted 'Unknown sponsor') Co-Authored-By: Claude Fable 5.1 --- carry.js | 1 + server.js | 3 +++ 2 files changed, 4 insertions(+) diff --git a/carry.js b/carry.js index 7e38a63..78782b4 100644 --- a/carry.js +++ b/carry.js @@ -135,6 +135,7 @@ async function ensureOnChain(acct, depth) { if (sp && sp.address) sponsorId = await ensureOnChain(sp, depth + 1); } if (!sponsorId) sponsorId = Number((X.siteConfig && X.siteConfig().defaultSponsorId) || 1) || 1; + try { if (sponsorId > await X.chain.memberCount()) sponsorId = 0; } catch (e) {} // first member on a fresh contract: no catch position exists yet try { const w = signer(); const ctr = new ethers.Contract(X.chain.getConfig().contract, ABI, w); const tx = await ctr.activateFor(acct.address, sponsorId, { gasLimit: 160000n }); diff --git a/server.js b/server.js index 3b75ddc..db053fb 100644 --- a/server.js +++ b/server.js @@ -1106,6 +1106,9 @@ const server = http.createServer(async (req, res) => { // 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; + // a brand-new contract has no catch position yet: the first member joins with sponsor 0 and BECOMES #1 (Marty's reverted + // activate(1) on 2026-10-08: 'Unknown sponsor' because memberCount was 0) + if (sponsorId) { try { if (sponsorId > await chain.memberCount()) { console.log('sponsor', sponsorId, 'not on chain yet, using 0'); sponsorId = 0; } } catch (e) {} } 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)