Repository navigation
Expand file tree
/
Copy pathv2-sync.js
More file actions
1 lines (1 loc) · 2.37 KB
/
Copy pathv2-sync.js
File metadata and controls
1 lines (1 loc) · 2.37 KB
1
(async function(){'use strict';const SYNC='0x6368e007b9f0b941560ed1f3bceb20247f5eca37',API='https://api.par.family',RPC='https://rpc.mainnet.chain.robinhood.com/',$=id=>document.getElementById(id),INITIAL=1000000000n*10n**18n;function fmt(n,max=4){n=Number(n);if(!Number.isFinite(n))return'—';return n.toLocaleString('en-US',{maximumFractionDigits:max})}function raw(raw,dec=18,max=2){try{const n=BigInt(raw||0),base=10n**BigInt(dec),whole=n/base,rem=n%base;const frac=(rem.toString().padStart(dec,'0').slice(0,max)).replace(/0+$/,'');return Number(whole).toLocaleString('en-US')+(frac?'.'+frac:'')}catch{return'—'}}function quote(m){const x=m?.lastPriceQuoteX18;if(x==null)return null;const d=Number(m?.quoteDecimals??18);return Number.parseFloat(String(x))/10**d}try{const r=await fetch(`${API}/launches/${SYNC}`,{cache:'no-store'});if(!r.ok)throw 0;const d=await r.json(),ms=Array.isArray(d.markets)?d.markets:[];const net=ms.find(m=>String(m.quoteSymbol||'').toUpperCase()==='NET'),usd=ms.find(m=>String(m.quoteSymbol||'').toUpperCase()==='USDG');$('syncNet').textContent=net&"e(net)!=null?fmt(quote(net),8)+' NET':'—';$('syncUsd').textContent=usd&"e(usd)!=null?'$'+fmt(quote(usd),8):'—';$('syncStatus').textContent='LIVE PAR DATA'}catch{$('syncStatus').textContent='PAR DATA UNAVAILABLE'}try{const v=await import('/vendor/viem.js'),chain=v.defineChain({id:4663,name:'Robinhood Chain',nativeCurrency:{name:'Ether',symbol:'ETH',decimals:18},rpcUrls:{default:{http:[RPC]}}}),c=v.createPublicClient({chain,transport:v.http(RPC,{timeout:12000,retryCount:1})}),s=await c.readContract({address:SYNC,abi:[{type:'function',name:'totalSupply',stateMutability:'view',inputs:[],outputs:[{type:'uint256'}]}],functionName:'totalSupply'});$('supply').textContent=raw(s,18,2);$('burned').textContent=raw(INITIAL>s?INITIAL-s:0n,18,2)}catch{$('supply').textContent='—';$('burned').textContent='—'}try{const r=await fetch(`${API}/distributions?token=${SYNC}`,{cache:'no-store'});if(!r.ok)throw 0;const d=await r.json(),t=Array.isArray(d.totals)?d.totals:[];for(const [symbol,id] of [['NET','netDistributed'],['USDG','usdgDistributed'],['SYNC','syncDistributed']]){const x=t.find(y=>String(y.symbol||'').toUpperCase()===symbol);$(id).textContent=x?raw(x.amount??x.total??x.rawAmount,Number(x.decimals??18),2):'0'}}catch{['netDistributed','usdgDistributed','syncDistributed'].forEach(id=>$(id).textContent='—')}})();