// Contract proof page (trust pack): live facts from /api/contract (read from Polygon, cached 5 minutes on the server).
(async function () {
FX.renderNav('/contract'); FX.renderFooter();
const el = document.getElementById('facts'); const esc = FX.esc;
let d; try { d = await FX.getJSON('/api/contract'); } catch (e) { d = {}; }
const ex = d.explorer || 'https://polygonscan.com';
const addr = (a, note) => a ? '' + esc(a) + '' + (note ? '
' + note + '' : '') : 'not read yet';
const sp = d.split || { sponsorPct: 25, levelPct: 5, potPct: 10, companyPct: 45, maxDepth: 20 };
const splitRow = ['The split', 'Sponsor ' + sp.sponsorPct + '%, levels 2 to 5 ' + sp.levelPct + '% each, Best Coach pot ' + sp.potPct + '%, 5xYourTeam ' + sp.companyPct + '%. Someone in the line with no position is passed over and the share goes up to the next person who holds one, up to ' + sp.maxDepth + ' places. Fixed in the code: no setter can change it.'];
if (!d.address) { el.innerHTML = '
| Status | The contract is not live yet. Its address, owner, prize pot wallet and every position will show here, read straight from Polygon. |
|---|
| ' + splitRow[0] + ' | ' + splitRow[1] + ' |
'; return; }
const rows = [
['Contract', addr(d.address, 'DraftPosition on ' + (d.chainId === 137 ? 'Polygon' : 'chain ' + d.chainId))],
['Source code', 'Verified source on Polygonscan and Sourcify: ' + esc(d.verified && d.verified.polygonscan === 'pending' ? 'pending' : 'done')],
['Owner', addr(d.owner, 'A Tangem hardware wallet. It can pause new sales, set the price of future positions and change the keeper. It cannot move anyone\'s money or change the split.')],
['Company', addr(d.company, '5xYourTeam. Fixed in the contract when it was deployed.')],
['Best Coach pot', addr(d.prizeWallet, 'Receives 10% of every position in the same transaction. Fixed in the contract when it was deployed. Each payout from it is listed on the ledger.')],
['Keeper', addr(d.keeper, 'The site\'s signing key. It only signs a buyer\'s sponsor line from the network hub, once, on their first position.')],
splitRow,
['Position', '$' + esc(d.position && d.position.usd) + ' one-time, paid in POL at the live Chainlink price' + (d.priceCents ? ' (contract price: $' + (d.priceCents / 100).toFixed(2) + ')' : '')],
['Sales', d.live ? (d.paused ? 'Paused' : 'Open') + ' ยท ' + FX.n(d.orderCount) + ' orders so far' : '' + esc(d.error || 'not read yet') + ''],
['Held by the contract', d.live ? FX.polOf(d.balanceWei) + ' POL' + (BigInt(d.totalOwedWei || 0) > 0n ? ' (all of it owed to wallets whose payment bounced, waiting for them to claim)' : ' (nothing is kept: every position is paid out in the same transaction)') : 'not read yet']
];
el.innerHTML = '' + rows.map(r => '| ' + r[0] + ' | ' + r[1] + ' |
').join('') + '';
})();