Skip to content

Instantly share code, notes, and snippets.

@strictlymomo
Created June 10, 2021 18:37
Show Gist options
  • Save strictlymomo/5f76ed2e14ef41435f0f6757420690a8 to your computer and use it in GitHub Desktop.
Save strictlymomo/5f76ed2e14ef41435f0f6757420690a8 to your computer and use it in GitHub Desktop.
Fix for burned avax
var formatter = new Intl.NumberFormat('en-US', {style: 'currency',currency: 'USD'});
function video() {let v = $('.section-hero .home-sectionhero-video iframe');v.attr('src','https://player.vimeo.com/video/543209885?api=1&background=1&autoplay=1&loop=1&muted=1');v.attr('webkitallowfullscreen mozallowfullscreen allowfullscreen');iframe = $('.section-hero .home-sectionhero-video iframe')[0];iframe = $(iframe);}
if ($('.section-hero .home-sectionhero-video iframe').length) {video();}
function header() {let h = 'header';let w = $('header + div').hasClass('style-white-header');if (w) $(h).addClass('style-white');$(window).scroll(function () {if ($(this).scrollTop() >= 1) {$(h).addClass('style-scroll');if (w) $(h).removeClass('style-white');} else {if (!$(h).hasClass('style-open')) {$(h).removeClass('style-scroll');if (w) $(h).addClass('style-white');}}});$('header .header-action').click(function () {if ($(h).hasClass('style-open')) {$(h).removeClass('style-open')} else {$(h).addClass('style-open');$(h).addClass('style-scroll');if (w) $(h).removeClass('style-white')}})}
function footer() {let f = 'footer .footer-containerfoot-containerlang'; $(`${f}-lang`).click(function () {if ($(f).hasClass('style-show')) {$(f).removeClass('style-show')} else {$(f).addClass('style-show')}})}
function sliderDevelopersPage() {let s = '.section-quote .wrapper .section-quote_containerslider .section-quote_el'; let sqn = '.section-quote .wrapper .section-quote_containerslider .section-quote_containernav .section-quote_nav';let index = -1;let nbMax = $(s).length;let interval;let line = $('<div>', { class: 'section-quote_ellineprogress' });$(s + ' .section-quote_elcontainertext .section-quote_elcontainerinfos .section-quote_elprogress').append(line);$(s).addClass('style-hide');$(s + ':nth-child(1)').addClass('style-show');$(s + ':nth-child(1)').removeClass('style-hide');$(sqn + ' .section-quote_btnnext').click(function () {clearInterval(interval); $(s + ':nth-child(' + (index + 1) + ')').addClass('style-hide'); index--; if (index < 0) index = nbMax - 1;setTimeout(function () {$(s).removeClass('style-show'); $(s + ':nth-child(' + (index + 1) + ')').addClass('style-show'); setTimeout(function () { $(s + ':nth-child(' + (index + 1) + ')').removeClass('style-hide');}, 50)}, 500);startInterval();});$(sqn + ' .section-quote_btnprev').click(function () {clearInterval(interval); $(s + ':nth-child(' + (index + 1) + ')').addClass('style-hide');index++;if (index > nbMax - 1) index = 0;setTimeout(function () {$(s).removeClass('style-show');$(s + ':nth-child(' + (index + 1) + ')').addClass('style-show');setTimeout(function () {$(s + ':nth-child(' + (index + 1) + ')').removeClass('style-hide');}, 50)}, 500); startInterval();});function startInterval() { interval = setInterval(function () {$(sqn + ' .section-quote_btnnext').click()}, 7500)} startInterval();}
function sliderSolutionsPage() { let sss = '.section-solutions_solutioncontainer'; let e1 = sss + ' .section-solutions_containerel .section-solutions_el'; let ss = sss + ' .section-solutions_solutioncontainernav .section-solutions_solutioncontainerstep .section-solutions_solutionstep'; let nv = sss + ' .section-solutions_solutioncontainernav'; let square = $('<div>', { class: 'section-solutions_solutionstep' }); $('.section-solutions .wrapper .section-solutions_containersection .section-solutions_solution').each(function () {let section = $(this); let index = 1; let nbMax = Math.ceil(section.find(e1).length / 4); let interval; $(e1).addClass('style-hide'); setTimeout(function () {for (let i = 1; i <= 4; i++) {section.find(e1 + ':nth-child(' + i + ')').addClass('style-show').removeClass('style-hide')}}, 50); if (nbMax - 1 >= 1) {section.find(ss).remove();for (let i = 1; i <= nbMax; i++) {section.find(nv + ' .section-solutions_solutioncontainerstep').append(square.clone());} section.find(ss + ':first-child').addClass('style-active');} else {section.find(nv).remove();} section.find(nv + ' .section-solutions_solutionbtndown').click(function () {clearInterval(interval); for (let i = 1; i <= 4; i++) {section.find(e1 + ':nth-child(' + ((index - 1) * 4 + i) + ')').addClass('style-hide');} index++; if (index > nbMax) {index = 1;} section.find(ss + '.style-active').removeClass('style-active'); section.find(ss + ':nth-child(' + index + ')').addClass('style-active'); setTimeout(function () {section.find(e1).removeClass('style-show');for (let i = 1; i <= 4; i++) {section.find(e1 + ':nth-child(' + ((index - 1) * 4 + i) + ')').addClass('style-show')} setTimeout(function () {for (let i = 1; i <= 4; i++) {section.find(e1 + ':nth-child(' + ((index - 1) * 4 + i) + ')').removeClass('style-hide')}}, 50)}, 500); startInterval();}); section.find(nv + ' .section-solutions_solutionbtnup').click(function () {clearInterval(interval);for (let i = 1; i <= 4; i++) {section.find(e1 + ':nth-child(' + ((index - 1) * 4 + i) + ')').addClass('style-hide');} index--; if (index < 1) {index = nbMax} section.find(ss + '.style-active').removeClass('style-active'); section.find(ss + ':nth-child(' + index + ')').addClass('style-active'); setTimeout(function () { section.find(e1).removeClass('style-show'); for (let i = 1; i <= 4; i++) {section.find(e1 + ':nth-child(' + ((index - 1) * 4 + i) + ')').addClass('style-show');} setTimeout(function () { for (let i = 1; i <= 4; i++) { section.find(e1 + ':nth-child(' + ((index - 1) * 4 + i) + ')').removeClass('style-hide')}}, 50);}, 500); startInterval();}); function startInterval() {interval = setInterval(function () { section.find(nv + ' .section-solutions_solutionbtndown').click();}, 5000)} startInterval(); });}
function searchEcosystemPage() {let eh = ' .section-ecosystem_head'; let se = '.section-ecosystem'; let el = se + ' .section-ecosysteme_containerel .section-ecosystem_el'; let eltag = se + eh + ' .section-ecosystem_containertag .section-ecosystem_containereltag .section-ecosystem_eltag'; let celtag = se + eh + ' .section-ecosystem_containertag .section-ecosystem_containereltag'; let form = se + eh + ' .section-ecosystem_containersearch form';function updateEcosystemEl() { $(el).parent().removeClass('style-hide'); $(el).each(function () {let elTag = $(this);let tagCheck = false;elTag.find('.section-ecosystem_eltext .section-ecosystem_elcontainertag .section-ecosystem_eltag').each(function () {let val = $(this).find('.styleparagraphtiny').text().toLowerCase();if ($(eltag).length > 0) {$(eltag).each(() => { if (val.toLowerCase() == $(this).find('.styleparagraphtiny').text().toLowerCase()) tagCheck = true})}});if ($(eltag).length > 0) {if (!tagCheck) elTag.parent().addClass('style-hide')}})}$(el).mouseenter(function () {$(this).addClass('style-hover')}); $(el).mouseleave(function () {$(this).removeClass('style-hover')}); $(form).submit(function () {return false}); $(form).submit(function () {return false}); $(form + ' input').on('keyup', function () {$(eltag).remove(); var value = $(this).val().toLowerCase();if (value.length > 0) { $(el).each(function () { let se = $(this).find(".section-ecosystem_eltext"); if (se.find('h4').text().toLowerCase().indexOf(value) == -1 && se.find('p').text().toLowerCase().indexOf(value) == -1 && se.find('.section-ecosystem_eltag div').text().toLowerCase().indexOf(value) == -1) { $(this).parent().addClass('style-hide')} else { $(this).parent().removeClass('style-hide')}})} else {$(el).parent().removeClass('style-hide')}}); let cTag = $('<div>', { class: 'section-ecosystem_containereltag' }), tag = $('<div>', { class: 'section-ecosystem_eltag' }), tagText = $('<div>', { class: 'styleparagraphtiny' }), tagCross = $('<div>', { class: 'section-ecosystem_tagcross' }); tag.append(tagText); tag.append(tagCross); $('.section-ecosystem .section-ecosystem_head .section-ecosystem_containertag').append(cTag); $('.section-ecosystem .section-ecosystem_head .section-ecosystem_containertag .w-form form select').change(function () {$(form + ' input').val(''); $(celtag + ' .section-ecosystem_eltag .section-ecosystem_tagcross').unbind('click'); let val = $(this).val(); if (val.length > 0) { let tagCopy = tag.clone(); tagCopy.find('.styleparagraphtiny').text(val); let add = true; $(eltag).each(function () {if ($(this).find('.styleparagraphtiny').text().toLowerCase() == val.toLowerCase()) {add = false;}}); if (add) { $(celtag).append(tagCopy); $(celtag + ' .section-ecosystem_eltag .section-ecosystem_tagcross').click(function () {$(this).parent().remove(); updateEcosystemEl();}); updateEcosystemEl();}}})}
function pressHomePage() {if (window.matchMedia('(min-width: 700px)').matches) { $('.section-press_el img').click(function () {$('.section-press_el').removeClass('section-press_elactive'); $(this).parent().addClass('section-press_elactive');})} else {$('.section-press_el').addClass('section-press_elactive')}}
function formContactPage() {let s = '.section-contactform .section-contactform_containertext form .section-contactform_containerinput'; $(s).focusin(function () {$(this).addClass('style-focus')}); $(s).focusout(function () {$(this).removeClass('style-focus')});}
function formAvalanchecontactPage() {let s = '.section-applicationform .section-applicationform_containerform form .section-applicationform_input'; $(s).focusin(function () {$(this).addClass('style-focus')}); $(s).focusout(function () {$(this).removeClass('style-focus')});}
function getPriceAndStakes() {const priceURL = 'https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=avalanche-2&order=market_cap_desc&per_page=100&page=1&sparkline=false', url = 'https://api.avax.network/ext/P', ct = 'application/json', p = '11111111111111111111111111111111LpoYY', AVAX = Math.pow(10, 9); let totalS = 0, currSupply = 0, price = 0;/* GET PRICE */fetch(priceURL).then((res) => res.json()).then((data) => {price = data[0].current_price; $('#price').html(`$${data[0].current_price}`); $('#mcap').html(`$${data[0].market_cap.toLocaleString()}`); $('#vol').html(`$${data[0].total_volume.toLocaleString()}`);/* GET CURRENT VALIDATORS*/ $.ajax({url: url,type: 'POST',data: JSON.stringify({jsonrpc: '2.0',method: 'platform.getCurrentValidators',params: { subnetID: p },id: 1,}),contentType: ct,dataType: 'json', success: function (d, s) { let v = d.result.validators; /* CALC TOTAL STAKE & DELEGATIONS */ let dCount = 0, totalVS = 0, totalDS = 0; v.forEach(v => {d = v.delegators; const [s, ds] = calcStake(d, v.stakeAmount); totalVS += parseInt(s); totalDS += ds; if (d) dCount += d.length;}); totalS = parseFloat(((totalVS + totalDS) / AVAX).toFixed(2)); /* BIND DATA TO VALIDATOR STATS */ $('#tVal').html(v.length.toLocaleString()); $('#tDel').html(dCount.toLocaleString()); $('#sTotal').html(totalS.toLocaleString()); $('#sVal').html(parseFloat((totalVS / AVAX).toFixed(0)).toLocaleString()); $('#sDel').html(parseFloat((totalDS / AVAX).toFixed(0)).toLocaleString()); /* GET CURRENT SUPPLY */ $.ajax({url: url,type: 'POST',data: JSON.stringify({jsonrpc: '2.0',method: 'platform.getCurrentSupply',params: {},id: 1,}),contentType: ct,dataType: 'json', success: function (d, s) {/* CALC STAKING RATIO & APY */currSupply = (parseInt(d.result.supply) / AVAX).toFixed(2); const apy = (calcReward(currSupply, 31536000, currSupply) / currSupply) *100; $('#ratio').html(`${((totalS / currSupply) * 100).toFixed(2)}%`); $('#stakep').html(`${((totalS / currSupply) * 100).toFixed(2)}%`); $('#apy').html(`${apy.toFixed(2)}%`); $('#yourAPY').html(`${apy.toFixed(2)}%`); setRewards(100, currSupply, price); let doInput = (event) => handleStakingCalc(event, [currSupply, price]); $('#calcu').on('propertychange input', doInput); $('#calcu').focusin(function () {$(this).addClass('style-focus')}); $('#calcu').focusout(function () {$(this).removeClass('style-focus')});},})}})});/* PENDING */ $.ajax({url: url,type: 'POST',data: JSON.stringify({jsonrpc: '2.0',method: 'platform.getPendingValidators',params: { subnetID: p },id: 1,}),contentType: ct,dataType: 'json',success: function (d, s) {$('#pVal').html(`${d.result.validators.length.toLocaleString()} pending`);$('#pDel').html(`${d.result.delegators.length.toLocaleString()} pending`)},})}
function individuals() {fetch('https://api.avax.network/ext/bc/C/rpc', {method: 'POST',mode: 'cors',cache: 'no-cache',credentials: 'same-origin',headers: { 'Content-Type': 'application/json' },redirect: 'follow',referrerPolicy: 'no-referrer',body: JSON.stringify({jsonrpc: '2.0',method: 'eth_getBalance',params: ['0x0100000000000000000000000000000000000000', 'latest'],id: 1,}),}).then((res) => res.json()).then((data) => {burned = parseInt(data.result) / Math.pow(10, 18); str = parseFloat(burned.toFixed(2)).toLocaleString(); $('#burned').html(`${str} AVAX`);});fetch('https://explorerapi.avax.network/v2/cacheaddresscounts').then((res) => res.json()).then((data) => {let wallets = parseInt(data[0].total) + parseInt(data[1].total);$('#wals').html(wallets.toLocaleString())});}
$(window).on('load', function () { if (window.location.href.indexOf('validators') > -1) { getPriceAndStakes() } if (window.location.href.indexOf('individuals') > -1) { getPriceAndStakes(); individuals();} sliderDevelopersPage(); sliderSolutionsPage(); searchEcosystemPage(); pressHomePage(); formContactPage(); formAvalanchecontactPage(); footer(); $('.buttontop').click(() => $('html,body').animate({scrollTop: 0}, 'slow'))}); header();
// HELPERS
function calcStake(d, amt) { let dS = 0; if (d) d.forEach(d => dS += parseInt(d.stakeAmount)); return [parseInt(amt), dS];}
function calcReward(amt, dur, currSup) { const maxC = 0.12, minC = 0.1, diff = maxC - minC, maxSup = 720000000, remSup = maxSup - currSup, ratioSup = amt / currSup, maxDur = 31536000 /*1 yr in sec*/, ratioDur = dur / maxDur, mintingRate = minC + diff * ratioDur; let reward = remSup * ratioSup * (mintingRate * ratioDur); return reward;}
function handleStakingCalc(e, arg) { let valueChanged = false; valueChanged = (e.type == 'propertychange') ? e.originalEvent.propertyName == 'value' : true; if (valueChanged) setRewards(e.target.value, arg[0], arg[1]);}
function setRewards(stake, currSupply, price) { $('#yourStake').html(stake); let yearly = parseFloat(calcReward(stake,31536000,currSupply).toFixed(2)), monthly = parseFloat((yearly / 12).toFixed(2)), daily = parseFloat((yearly / 365).toFixed(2)); $('#yearly').html(`${yearly.toLocaleString()} AVAX`);$('#monthly').html(`${monthly.toLocaleString()} AVAX`);$('#daily').html(`${daily.toLocaleString()} AVAX`);$('#yUSD').html(`${formatter.format(yearly * price)}`);$('#mUSD').html(`${formatter.format(monthly * price)}`);$('#dUSD').html(`${formatter.format(daily * price)}`);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment