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_blue_logo.png" width="100%" /></header>

<main>
  
  <p><input name="network" placeholder="Enter network (none for mainnet)" /> <input name="block" placeholder="Enter block number (none for latest)" />
    <button name="start">Start</button></p>
  <section>
    <div>
      <p id="network"><strong>Network:</strong> <var>...</var></p>
      <p class="helper-text">The breakdown of all synths currently issued</p>
      <table cellpadding=0 cellspacing=0>
        <thead>
          <tr>
            <th></th>
            <th></th>
            <th></th>
            <th>Synth</th>
            <th>Rate</th>
            <th>Total Supply</th>
            <th>USD Value</th>
            <th>Percentage</th>
            <th>Non-Zero</th>
            <th></th>
            <th>Inverse Lower</th>
            <th>Inverse Entry</th>
            <th>Inverse Upper</th>
        </thead>
        <tbody>
        </tbody>
      </table>

      <dl>
          <dt>Total USD value of Synths</dt>
          <dd id="synthsTotal"></dd>
          <dt>SNXUSD price</dt>
          <dd id="snxusdPrice"></dd>
      </dl>
    </div>
   </div>
    
  </section>
  <div><div><h1>Compare Synths</h1><div id="graphCompare"><p class="helper-text">The breakdown of all synths (excluding sUSD)</p></div></div>
      <!--div><h1>Total Issued Over Time</h1><div id="graphTotalIssued"><p class="helper-text">The total issued synths over time (roughly one day per point)....</p></div></div-->
      
  
</main>
              
            
!

CSS

              
                @snx-color: #004433;

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

header {
  background-color: #0b0816;
  min-height: 50px;
}

main {
  section {
     display: flex;

     > div {
       width: 50%;
    }
    > div:nth-child(2) {
      width: calc(50% - 40px);
      margin-left: 40px;
     }
  }
  padding: 10px;
}

input { 
  width: 200px; 
  padding: 5px;
}

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
	}
	&#cancel {
		background-color: red;
	}
}

table {
  padding: 0;

  td, th {
    padding: 8px
  }
  tr:nth-child(even) {background: #EEE}
  tr {
    &.market-closed {
      opacity: 0.5;
    }
    &.frozen {
      color: #6b77ff;
    }
    &.suspended {
      color: red;
    }
    &.stale {
      background-color: orange;
    }
    &.flagged {
      background-color: yellow;
    }
  }
}

.helper-text {
  color: #CCC;
  font-size: 12px; 
}
              
            
!

JS

              
                
const tbodyTarget = document.querySelector('tbody');
const inputTarget = document.querySelector('input[name=network]');
const blockTarget = document.querySelector('input[name=block]');
const graphTarget = document.querySelector('#graphCompare');
//const graphTotalIssuedTarget = document.querySelector('#graphTotalIssued');

const networkTarget = document.querySelector('#network var');

const SUPPORTED_NETWORKS = {
  'mainnet': 1,
  'ropsten': 3,
  'rinkeby': 4,
  'kovan': 42,
};

const loadingGIF = '<img src="https://media.giphy.com/media/TvLuZ00OIADoQ/giphy.gif" width=150 />';

const start = async () => {
  tbodyTarget.innerHTML = loadingGIF;
  graphTarget.innerHTML = loadingGIF;
//  graphTotalIssuedTarget.innerHTML = loadingGIF;
  
  const network = (inputTarget.value.toLowerCase() in SUPPORTED_NETWORKS) ?  inputTarget.value.toLowerCase() : 'mainnet';
  
  networkTarget.innerHTML = network;
  
  const networkId = SUPPORTED_NETWORKS[network];
  const snxjs = new SynthetixJs.SynthetixJs({ networkId }); 
  const toUtf8Bytes = SynthetixJs.SynthetixJs.utils.formatBytes32String;
  const formatEther = snxjs.utils.formatEther;
  
  const fromBlock = blockTarget.value;
  const blockOptions = fromBlock ? { blockTag: Number(fromBlock) } : {};
  
  const synths = snxjs.contractSettings.synths.map(({ name }) => name);
  let totalInUSD = 0;
  const snxPrice = await snxjs.ExchangeRates.contract.rateForCurrency(toUtf8Bytes('SNX'), blockOptions) / 1e18;
  let results = await Promise.all(synths.map(async synth => {
    const totalAmount = await snxjs[synth].contract.totalSupply(blockOptions);
      
    const totalSupply = formatEther(totalAmount);  
    const rateForSynth = await snxjs.ExchangeRates.contract.rateForCurrency(toUtf8Bytes(synth), blockOptions) / 1e18;
    const totalSupplyInUSD = rateForSynth * totalSupply;
    totalInUSD += totalSupplyInUSD;
    const rateIsFrozen = await snxjs.ExchangeRates.contract.rateIsFrozen(toUtf8Bytes(synth), blockOptions);
    const rateIsStale = await snxjs.ExchangeRates.contract.rateIsStale(toUtf8Bytes(synth), blockOptions);
    const rateIsFlagged = await snxjs.ExchangeRates.contract.rateIsFlagged(toUtf8Bytes(synth), blockOptions);
    let inverseBounds;
    if (/^i/.test(synth)) {
      inverseBounds = await snxjs.ExchangeRates.contract.inversePricing(toUtf8Bytes(synth), blockOptions);
    }
    const { suspended: marketClosed } = await snxjs.SystemStatus.contract.synthExchangeSuspension(toUtf8Bytes(synth), blockOptions);
    const { suspended, reason } = await snxjs.SystemStatus.contract.synthSuspension(toUtf8Bytes(synth), blockOptions);
    
    return { synth, totalAmount, totalSupply, rateForSynth, totalSupplyInUSD, rateIsFrozen, rateIsStale, rateIsFlagged, marketClosed, suspended, reason: reason.toString(), inverseBounds };
  }));
  
  results = results.sort((a, b) => a.totalSupplyInUSD > b.totalSupplyInUSD ? -1 : 1);
  tbodyTarget.innerHTML = '';
  results.forEach(({ synth, rateForSynth, totalSupply, totalSupplyInUSD, rateIsFrozen, rateIsStale, rateIsFlagged, marketClosed, suspended, reason, inverseBounds }, i) => {
    tbodyTarget.innerHTML += `<tr class="${rateIsFrozen && 'frozen'} ${rateIsStale && 'stale'} ${rateIsFlagged && 'flagged'} ${marketClosed && 'market-closed'} ${suspended && 'suspended'}"><td>${i+1}</td><td><img width=32 src="https://raw.githubusercontent.com/Synthetixio/synthetix-assets/master/synths/${synth}.svg" /></td>
    <td style="font-size: 24px;">
      <span title="Synth suspended reason: ${reason}!">${suspended ? '⚠️('+reason+')' : ''}</span>
      <span title="Rate is frozen">${rateIsFrozen ? '❄️' : ''}</span>
      <span title="Rate is stale">${rateIsStale ? '🥨' : ''}</span>
      <span title="Rate is flagged">${rateIsFlagged ? '🏴‍☠️' : ''}</span>
      <span title="Market Closed">${marketClosed ? '💤' : ''}</span>
    </td><td>${synth}</td><td>${numbro(rateForSynth).format('0.0000')}</td><td>${numbro(totalSupply).format('0,000.0000')} ${synth}</td><td>${numbro(totalSupplyInUSD).format('0,000.00')}</td><td>${numbro(100*totalSupplyInUSD/totalInUSD).format('0.00')}%</td>
<td>${totalSupply > 0 ? '✅' : '❌'}</td>
<td><a target=_blank href="http://api.ethplorer.io/getTopTokenHolders/${snxjs[synth].contract.address}?apiKey=freekey&limit=100">Holders</a></td>
<td>${inverseBounds ? numbro(inverseBounds.lowerLimit / 1e18).format('0,000.00') : ''}</td>
<td>${inverseBounds ? numbro(inverseBounds.entryPoint / 1e18).format('0,000.00') : ''}</td>
<td>${inverseBounds ? numbro(inverseBounds.upperLimit / 1e18).format('0,000.00') : ''}</td>
</tr>`;
  });
  
  document.querySelector('#synthsTotal').innerHTML = numbro(totalInUSD).format('0,000.00');
  document.querySelector('#snxusdPrice').innerHTML = numbro(snxPrice).format('0.0000');
   
  const resultsWithValues = results.filter(({ totalSupplyInUSD }) => Number(totalSupplyInUSD) > 100);
  
  new frappe.Chart(graphTarget, {  
    title: 'Top 10 Synth Breakdown (in millions)',
    data: {
      labels: resultsWithValues.slice(0, 10).map(({ synth }) => synth),
      datasets: [
        {
          name: 'USD',
          values: resultsWithValues.slice(0, 10).map(({ totalSupplyInUSD }) => totalSupplyInUSD/1e6)
        }
      ]
    },
    type: 'bar', 
    colors: ['#7cd6fd', '#743ee2']
  });
  
  /* Note: no longer works without a provider that supports blockTag (an archive node)
  // track total issued over time
  const currentBlock = await snxjs.contractSettings.provider.getBlockNumber();
  
  const totalIssuedPromises = [];
  for (i = 0; i < 10; i++) {
    const blockTag = Number(currentBlock) - 6000*i; // approx 1 day
    totalIssuedPromises.unshift(snxjs.Synthetix.contract.totalIssuedSynths(toUtf8Bytes('sUSD'), { blockTag }).then(res => ({
      rate: formatEther(res),
      block: blockTag
    })).catch(() => {})); 
  }
  
  const totalIssued = await Promise.all(totalIssuedPromises);
  
  console.log(totalIssued);

  new frappe.Chart(graphTotalIssuedTarget, {  
    title: 'Synthetix.totalIssuedSynths over time (by block number, in millions)',
    data: {
      labels: totalIssued.filter(e => e).map(({ block }) => block/1e6),
      datasets: [
        {
          name: 'USD',
          values: totalIssued.filter(e => e).map(({ rate }) => rate/1e6)
        }
      ]
    },
    type: 'line'
//    type: 'bar', 
//    colors: ['#7cd6fd', '#743ee2']
  });
  */
};

document.querySelector('button[name=start]').addEventListener('click', start);
              
            
!
999px

Console