Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <header><img src="https://docs.synthetix.io/img/logos/synthetix_text_logo_white.png" /></header>

<main>
  <button name="begin">Begin</button>
  <button name="stop">Stop</button> 
  
    <ul>
      <li id="headBlock"><strong>HEAD Block:</strong><var>?</var></li>
      <li id="snxPrice"><strong>SNX Price:</strong><var>?</var></li>
      <li id="snxSupply"><strong>SNX Total Supply:</strong><var>?</var></li>
      <li id="snxMarketCap"><strong>SNX Market Cap:</strong><var>?</var></li>
      <li id="debtPool"><strong>Debt Pool:</strong><var>?</var></li>
      <li id="networkRatio"><strong>Network Ratio:</strong><var>?</var></li>
      <li id="tokenHolders"><strong>Token Holders:</strong><var>?</var></li>
      <li id="neverIssued"><strong>Never Issued:</strong><var>?</var></li>
      <li id="snxTotal"><strong>SNX Current Total:</strong><var>?</var></li>
      <li id="snxLocked"><strong>SNX Current Locked:</strong><var>?</var></li>
      <li id="pcentLocked"><strong>&nbsp;</strong><var>?</var></li>
      <li id="activeRatio"><strong>Active Ratio:</strong><var>?</var></li>
    </ul>
  
  <table>
    <thead><tr><th></th><th>Address</th><th>Balance</th><th>CRatio</th><th>Locked SNX</th><th>Debt Balance</th><th>% of Pool</th></tr></thead>
    <tbody><tr><td colspan="100" class="helper-text">Press Begin to start....</td></tr></tbody>
  </table>
</main>

              
            
!

CSS

              
                @snx-color: #0b0816;

body {
  font-family: 'Helvetica';
	font-size: 14px;
  padding: 0;
  margin: 0;
}

header {
  background-color: @snx-color;
  min-height: 50px;
  img {
    padding: 8px;
  }
}

main {
  padding: 20px;
}

button {
	margin: 0px 0px 20px 0;
	padding: 10px 20px;
	font-size: 14px;
	border-radius: 4px;
	background-color: @snx-color;
	color: white;
	font-weight: bold;
	opacity: 0.8;
	cursor: pointer;
	&:hover {
		opacity: 1
	}
	&[name=stop] {
		background-color: red;
	}
}

ul {
	padding: 0;
	li {
		padding-left: 3px;
		list-style-type: none;
		strong {
			display: inline-block;
			width: 160px;
		}
	}
}

var {
	font-family: "Courier New", "Courier";
	font-size: 18px;
}

.leaderboard { 
	display: flex;
	> * {
		width: 50%;
	}
}

a {
	color: @snx-color;
}

table {
	width: 100%;
	th, td {
		text-align: right;
	}
	tr:nth-child(even) {
		background-color: #e8e8e8;
	}
}

.helper-text {
	color: #aaa;
	font-size: 12px;
}
.error-text {
	color: red;
}
.success-text {
	color: green;
	a {
		color: darkgreen;
	}
}
              
            
!

JS

              
                window.CP.PenTimer.MAX_TIME_IN_LOOP_WO_EXIT = 60e3; // 1min timeout on for loop below

const snxjs = new SynthetixJs.SynthetixJs(); 
const toUtf8Bytes = SynthetixJs.SynthetixJs.utils.formatBytes32String;
const tbody = document.querySelector('tbody');

const beginBtn = document.querySelector('button[name="begin"]');
const stopBtn = document.querySelector('button[name="stop"]');
const headBlockTarget = document.querySelector('#headBlock var');
const debtPoolTarget = document.querySelector('#debtPool var');
const snxSupplyTarget = document.querySelector('#snxSupply var');
const snxMarketCapTarget = document.querySelector('#snxMarketCap var');
const tokenHoldersTarget = document.querySelector('#tokenHolders var');
const snxPriceTarget = document.querySelector('#snxPrice var');
const snxTotalTarget = document.querySelector('#snxTotal var');
const snxLockedTarget = document.querySelector('#snxLocked var');
const pcentLockedTarget = document.querySelector('#pcentLocked var');
const neverIssuedTarget = document.querySelector('#neverIssued var');
const networkRatioTarget  = document.querySelector('#networkRatio var');
const activeRatioTarget  = document.querySelector('#activeRatio var');

let stopFlag = false;

stopBtn.addEventListener('click', () => stopFlag = true);

const lookup = async () => {
  tbody.innerHTML = '<img src="https://media.giphy.com/media/TvLuZ00OIADoQ/giphy.gif" width=150 />';
  beginBtn.setAttribute('disabled', true);
  try {
    tokenHoldersTarget.innerHTML = 0;
    neverIssuedTarget.innerHTML = 0;
    tbody.innerHTML = '<tr><td colspan=100 class="helper-text">loading...</td></tr>';
    const headBlock = await snxjs.contractSettings.provider.getBlockNumber();
    headBlockTarget.innerHTML = headBlock;
    // track block number so if this process takes a long time to render, 
    // results will be consistent
    const blockTag = { blockTag: headBlock };
    const holders = await snxData.snx.holders({ max: 5000 }); 
    const escrowContracts = await Promise.all([snxjs.AddressResolver.getAddress(toUtf8Bytes('SynthetixEscrow')), snxjs.AddressResolver.getAddress(toUtf8Bytes('RewardEscrow'))]);
    
    const exchangeWalletsReq = await fetch('https://raw.githubusercontent.com/whjn011205/ScoreEngine/fe383336db49a7601f1793b8ad570a8d0a8fb6df/src/data/goodList.json');
    const exchangeWallets = await exchangeWalletsReq.json();
  
    const knownWallets = exchangeWallets.concat({ name: 'Synthetix: Foundation', exchange: '0x49BE88F0fcC3A8393a59d3688480d7D253C37D2A' }, { name: 'Uniswap SNX V1', exchange: '0x3958B4eC427F8fa24eB60F42821760e88d485f7F' }, { name: 'Synthetix: ArbRewarder', exchange: '0xA6B5E74466eDc95D0b6e65c5CBFcA0a676d893a4' }, {
      name: 'Kyber SNX Reserve', exchange: '0xa107dfa919c3f084a7893A260b99586981beb528'
    }, { name: 'Aave Lending Pool', exchange: '0x3dfd23A6c5E8BbcFc9581d2E864a68feb6a076d3' }, {
      name: 'Liquid', exchange: '0xedBB72E6b3Cf66a792bFF7FaaC5Ea769fe810517'
    }, { name: 'Unipool', exchange: '0x48D7f315feDcaD332F68aafa017c7C158BC54760' },
                                               {name: 'Synthetix: Airdropper', exchange: '0x3aa4907A38eE3ffA485CDEAa7bB1a2B7241F5dAA' }, {
      name: 'Eterbase', exchange: '0x8D76166C22658A144c0211d87Abf152e6a2d9D95'
    });
    
    // const issuanceRatioToAvoidPenalty = Number(snxjs.utils.formatEther(await snxjs.FeePool.getPenaltyThresholdRatio()));
    const totalSNXSupply = Number(snxjs.utils.formatEther(await snxjs.Synthetix.contract.totalSupply(blockTag)));
    snxSupplyTarget.innerHTML = numbro(Math.round(totalSNXSupply)).format('0,0');
    const totalIssuedSynths = Number(snxjs.utils.formatEther(await snxjs.Synthetix.contract.totalIssuedSynthsExcludeEtherCollateral(toUtf8Bytes('sUSD'), blockTag)));
    
    debtPoolTarget.innerHTML = '$' + numbro(Math.round(totalIssuedSynths)).format('0,0');
    
     const issuanceRatio = Number(snxjs.utils.formatEther(await snxjs.SynthetixState.issuanceRatio()));
    const results = holders.filter(({ address }) => escrowContracts.indexOf(address.toLowerCase()) === -1);
    
    //const sleep = ms => new Promise(res => setTimeout(res, ms));
    const usdToSnxPrice = snxjs.utils.formatEther(await snxjs.ExchangeRates.rateForCurrency(toUtf8Bytes('SNX')));
    
    snxPriceTarget.innerHTML = `$${Number(usdToSnxPrice).toFixed(5)}`;
    snxMarketCapTarget.innerHTML = '$' + numbro(Math.round(totalSNXSupply * usdToSnxPrice)).format('0,0');
    networkRatioTarget.innerHTML=`${Math.round(1 / (totalIssuedSynths / (totalSNXSupply * usdToSnxPrice)) * 100)}%`;
    
    let snxTotal = 0;
    let snxLocked = 0;
    let stakersTotalDebt = 0;
    let stakersTotalCollateral = 0;
    const updateTotals = ({ balance, lockedSnx, debtBalance }) => {
      if (Number(debtBalance) > 0) {
        stakersTotalDebt += Number(debtBalance);
        stakersTotalCollateral += Number(balance * usdToSnxPrice);
      }
      neverIssuedTarget.innerHTML = Number(neverIssuedTarget.innerHTML) + (Number(lockedSnx) > 0 ? 0 : 1);
      tokenHoldersTarget.innerHTML = Number(tokenHoldersTarget.innerHTML) + 1;
      snxTotal += Number(balance);
      snxLocked += Number(lockedSnx);
      snxTotalTarget.innerHTML = `${numbro(snxTotal).format('0,000.00')} (${numbro(snxTotal * usdToSnxPrice).format('0,0.00')} USD)`;
      snxLockedTarget.innerHTML = `${numbro(snxLocked).format('0,000.00')} (${numbro(snxLocked * usdToSnxPrice).format('0,0.00')} USD)`;
      pcentLockedTarget.innerHTML=`${Number(snxLocked/snxTotal*100).toFixed(2)}%`;
      
      activeRatioTarget.innerHTML=`${Number(1/(stakersTotalDebt/stakersTotalCollateral)*100).toFixed(2)}%`;
    }
    
    let row = 1;    
    for (const { address, collateral } of results) {
      const addressLink = `<a target="_blank" href="https://etherscan.io/address/${address}">${address}</a>`;

      const promises = await Promise.all([snxjs.Synthetix.contract.collateral(address, blockTag), snxjs.Synthetix.contract.collateralisationRatio(address, blockTag), snxjs.Synthetix.contract.debtBalanceOf(address, toUtf8Bytes('sUSD'), blockTag)]); 
      const [ balance, collateralRatio,debtBalance] = promises.map(snxjs.utils.formatEther);   
      
      // ignore if 0 balance
       if (Number(balance) <= 0) continue;
      
      const knownWallet = knownWallets.find(({ exchange }) => exchange.toLowerCase() === address.toLowerCase());
      
      const balanceFormatted = numbro(balance).format('0,000.00');
      const balanceUSD = numbro(balance * usdToSnxPrice);
      const balanceUSDFormatted = numbro(balanceUSD).format('0,000.00');
      const lockedSnx = balance * Math.min(1, collateralRatio/issuanceRatio);
     
      updateTotals({ balance, lockedSnx,  debtBalance });
      
      const currentCRatio = collateralRatio > 0 ? (1/collateralRatio)*100 : 0;
      tbody.innerHTML += `<tr><td>${row++}.</td><td>${knownWallet ? `<strong>${knownWallet.name}</strong>` : ''}  ${addressLink}</td><td>${balanceFormatted} ($${balanceUSDFormatted})</td><td>${Math.round(currentCRatio)}%</td><td>${Math.round((lockedSnx/balance) * 100)}%</td><td>${numbro(debtBalance).format('0,0.00')}</td><td>${(debtBalance/totalIssuedSynths * 100).toFixed(4)}</td></tr>`;
      
      if (stopFlag) break;
    }
    stopFlag = false;
  
  } catch (err) {
    tbody.innerHTML = `<span style="color:red">${err}</span>`;
  }
  tbody.querySelector('tr:first-child>td').innerHTML = '';
  beginBtn.removeAttribute('disabled');
};

beginBtn.addEventListener('click', async () => {
  await lookup();
});

              
            
!
999px

Console