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 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-08 06:41:54 -05:00
parent 55584a7007
commit ab65439ad4
2 changed files with 4 additions and 0 deletions
+1
View File
@@ -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 });