Skip to content

Commit

Permalink
Problem: Missing tezos page formula calculation and data table proces…
Browse files Browse the repository at this point in the history
…sing (fractalide#207).

Solution: Add tezos formula calculation and data table json processing.
  • Loading branch information
miguelsimoni committed Jan 26, 2019
1 parent d2c0e8d commit 5633904
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 36 deletions.
52 changes: 16 additions & 36 deletions content/stake-pool/tezos-xtz.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</div>
</div>

<div id="estimation" class="">
<div id="estimation">

<div class="row">
<div class="col-sm-offset-2 col-sm-8 col-xs-offset-1 col-xs-10 text-center">
Expand All @@ -65,7 +65,7 @@
</div>
<div class="math_field">
<div class="input-group">
<input type="text" class="form-control" aria-describedby="your-stake-addon">
<input type="text" class="form-control" aria-describedby="your-stake-addon" id="yourStake" value="1000">
<span class="input-group-addon darker" id="your-stake-addon"><img src="/img/stake-pools/tezos-currency-white-min.png" width="12px"/></span>
</div>
</div>
Expand All @@ -78,7 +78,7 @@
<b class="text_dark_blue">Estimated<br>Blocks Per Year</b>
</div>
<div class="math_value">
<span>491.520</span>
<span id="estiamatedBlocksPerYear" data-val="491520">491.520</span>
</div>
</div>
<div class="math_symbol math_symbol_times">
Expand All @@ -92,7 +92,7 @@
<b class="text_dark_blue">Baker Rewards<br>Per Block</b>
</div>
<div class="math_value">
<span>16</span>
<span id="bakerRewardsPerBlock">16</span>
</div>
</div>
<div class="math_symbol math_symbol_plus">
Expand All @@ -104,8 +104,8 @@
</div>
<div class="math_field">
<div class="input-group">
<input type="text" class="form-control" aria-describedby="your-stake-addon">
<span class="input-group-addon darker" id="your-stake-addon"><img src="/img/stake-pools/tezos-currency-white-min.png" width="12px"/></span>
<input type="text" class="form-control" aria-describedby="avg-fees-per-block-addon" id="averageFeesPerBlock" value="0">
<span class="input-group-addon darker" id="avg-fees-per-block-addon"><img src="/img/stake-pools/tezos-currency-white-min.png" width="12px"/></span>
</div>
</div>
</div>
Expand All @@ -117,7 +117,7 @@
<b class="text_dark_blue">Endorsement<br>Rewards Per Block</b>
</div>
<div class="math_value">
<span>2</span>
<span id="endorsementRewardsPerBlock">2</span>
</div>
</div>
<div class="math_symbol math_symbol_times">
Expand All @@ -128,7 +128,7 @@
<b class="text_dark_blue">Endorsement<br>Per Block</b>
</div>
<div class="math_value">
<span>32</span>
<span id="endorsementPerBlock">32</span>
</div>
</div>
<div class="math_symbol math_symbol_parenthesis_close">
Expand All @@ -142,7 +142,7 @@
<b class="text_dark_blue">Total Tezos<br>Supply</b>
</div>
<div class="math_value">
<span>763.3M</span>
<span id="totalTezosSupply" data-val="763300000">763.3M</span>
</div>
</div>
<div class="math_symbol math_symbol_divide">
Expand All @@ -154,8 +154,8 @@
</div>
<div class="math_field">
<div class="input-group">
<input type="text" class="form-control" aria-describedby="your-stake-addon">
<span class="input-group-addon darker" id="your-stake-addon"><b class="text_white">%</b></span>
<input type="text" class="form-control" aria-describedby="percentage-stake-addon" id="percentageOfTezThatStake" value="50">
<span class="input-group-addon darker" id="percentage-stake-addon"><b class="text_white">%</b></span>
</div>
</div>
</div>
Expand All @@ -167,7 +167,7 @@
<b class="text_dark_blue">Fractalide XTZ Stake<br>Pool Reward-Share</b>
</div>
<div class="math_value">
<span>85%</span>
<span id="fractalideXTZStakePoolRewardShare" data-val="0.85">85%</span>
</div>
</div>
<div class="math_symbol math_symbol_equal">
Expand All @@ -181,21 +181,21 @@
<div class="col-sm-offset-2 col-sm-4 col-xs-offset-1 col-xs-10 text-center">
<div class="border_blue">
<p class="text_dark_blue">Your Estimated Fractalide XTZ Stake Pool Rewards</p>
<h2 class="sub_heading_blue">87.58 <img src="/img/stake-pools/tezos-currency-blue-min.png" width="18px"/></h2>
<h2 class="sub_heading_blue"><span id="yourEstimated">87.58</span> <img src="/img/stake-pools/tezos-currency-blue-min.png" width="18px"/></h2>
</div>
</div>
<div class="col-sm-offset-0 col-sm-4 col-xs-offset-1 col-xs-10 text-center">
<div class="border_blue">
<p class="text_dark_blue">Your Estimated Fractalide XTZ Stake Pool Delegation Annual Reward Percentage</p>
<h2 class="sub_heading_blue">8.8 %</h2>
<h2 class="sub_heading_blue"><span id="yourEstimatedPercentage">8.8</span> %</h2>
</div>
</div>
</div>

</div>

<!-- kt1 data table -->
<div id="kt1" class="hidden">
<div id="kt1" style="display: none;">

<div class="row">
<div class="col-sm-offset-2 col-sm-8 col-xs-offset-1 col-xs-10 text-center">
Expand Down Expand Up @@ -242,27 +242,6 @@
</tr>
</thead>
<tbody>
<tr>
<td>26</td>
<td>19999.74</td>
<td>14.391045</td>
<td>14.391485</td>
<td class="text_blue">Paid out</td>
</tr>
<tr>
<td>26</td>
<td>19999.74</td>
<td>14.391045</td>
<td>14.391485</td>
<td class="text_blue">Paid out</td>
</tr>
<tr>
<td>26</td>
<td>19999.74</td>
<td>14.391045</td>
<td>14.391485</td>
<td class="text_blue">Paid out</td>
</tr>
</tbody>
</table>
</div>
Expand Down Expand Up @@ -331,3 +310,4 @@
</div>

<script src="/js/global.js"></script>
<script src="/js/tezos.js"></script>
166 changes: 166 additions & 0 deletions themes/fractalide/files/js/tezos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
$(document).ready(function () {

$("#yourStake,#averageFeesPerBlock,#percentageOfTezThatStake").change(calculateEstimation);

$('#yourAddress').on('keypress', function (e) {
if (e.which == 13) {
$("#estimation").hide();
$("#kt1").show();

//TODO: TEST - remove this...
loadBackereiData(backereiTestData);

//TODO: set the backerei.json url...
try{
$.getJSON("/here/goes/url/backerei.json", function (data) {
loadBackereiData(data);
});
}catch(err){
//TODO: error handling...
console.log(err);
}
}
});

});

function calculateEstimation() {
var yourStake = parseFloat($("#yourStake").val());
var estiamatedBlocksPerYear = parseFloat($("#estiamatedBlocksPerYear").data("val"));
var bakerRewardsPerBlock = parseFloat($("#bakerRewardsPerBlock").html());
var averageFeesPerBlock = parseFloat($("#averageFeesPerBlock").val());
var endorsementRewardsPerBlock = parseFloat($("#endorsementRewardsPerBlock").html());
var endorsementPerBlock = parseFloat($("#endorsementPerBlock").html());
var totalTezosSupply = parseFloat($("#totalTezosSupply").data("val"));
var percentageOfTezThatStake = parseFloat($("#percentageOfTezThatStake").val()) / 100;
var fractalideXTZStakePoolRewardShare = parseFloat($("#fractalideXTZStakePoolRewardShare").data("val"));
var yourEstimated = yourStake * estiamatedBlocksPerYear * (bakerRewardsPerBlock + averageFeesPerBlock + endorsementRewardsPerBlock * endorsementPerBlock) / totalTezosSupply / percentageOfTezThatStake * fractalideXTZStakePoolRewardShare;
$("#yourEstimated").html(yourEstimated.toFixed(2));
$("#yourEstimatedPercentage").html((yourEstimated/100).toFixed(1));
}

function loadBackereiData(data) {
var trs = [];
$.each(data.payoutsByCycle, function (key, val) {
var tr = ["<tr>"];
tr.push("<td>" + key + "</td>");
tr.push("<td>" + "..." + "</td>");
tr.push("<td>" + val.estimatedTotalRewards + "</td>");
tr.push("<td>" + "..." + "</td>");
tr.push("<td class=\"text_blue\">Paid out</td>");
tr.push("</tr>");
trs.push(tr.join(""));
});
$(".kt1_data table tbody").html(trs.join(""));
}

//TODO: remove this...
var backereiTestData = {
"payoutsByCycle": {
"56": {
"delegators": {
"KT1TqnJ4Mr9zX5NX4en45bq34NtCyZ8uQ5QD": {
"balance": "57539259",
"estimatedRewards": "63641"
}
},
"estimatedBakerRewards": {
"bondRewards": "119925127",
"feeRewards": "11230",
"looseRewards": "2",
"totalRewards": "119936359"
},
"estimatedTotalRewards": "120000000",
"fee": {
"denominator": 20,
"numerator": 3
},
"stakingBalance": "92219067948",
"stolenBlocks": []
},
"57": {
"delegators": {
"KT1TqnJ4Mr9zX5NX4en45bq34NtCyZ8uQ5QD": {
"balance": "115222149",
"estimatedRewards": "44577"
}
},
"estimatedBakerRewards": {
"bondRewards": "41947556",
"feeRewards": "7866",
"looseRewards": "1",
"totalRewards": "41955423"
},
"estimatedTotalRewards": "42000000",
"fee": {
"denominator": 20,
"numerator": 3
},
"stakingBalance": "92276750838",
"stolenBlocks": []
},
"58": {
"delegators": {
"KT1TqnJ4Mr9zX5NX4en45bq34NtCyZ8uQ5QD": {
"balance": "115222149",
"estimatedRewards": "57313"
}
},
"estimatedBakerRewards": {
"bondRewards": "53932572",
"feeRewards": "10114",
"looseRewards": "1",
"totalRewards": "53942687"
},
"estimatedTotalRewards": "54000000",
"fee": {
"denominator": 20,
"numerator": 3
},
"stakingBalance": "92276750838",
"stolenBlocks": []
},
"59": {
"delegators": {
"KT1TqnJ4Mr9zX5NX4en45bq34NtCyZ8uQ5QD": {
"balance": "226280248",
"estimatedRewards": "99929"
}
},
"estimatedBakerRewards": {
"bondRewards": "47882436",
"feeRewards": "17634",
"looseRewards": "1",
"totalRewards": "47900071"
},
"estimatedTotalRewards": "48000000",
"fee": {
"denominator": 20,
"numerator": 3
},
"stakingBalance": "92387808937",
"stolenBlocks": []
},
"60": {
"delegators": {
"KT1TqnJ4Mr9zX5NX4en45bq34NtCyZ8uQ5QD": {
"balance": "282533702",
"estimatedRewards": "239000"
}
},
"estimatedBakerRewards": {
"bondRewards": "91718823",
"feeRewards": "42176",
"looseRewards": "1",
"totalRewards": "91761000"
},
"estimatedTotalRewards": "92000000",
"fee": {
"denominator": 20,
"numerator": 3
},
"stakingBalance": "92444062391",
"stolenBlocks": []
}
}
};

0 comments on commit 5633904

Please sign in to comment.