-
Notifications
You must be signed in to change notification settings - Fork 30
/
curation_calculator.html
511 lines (422 loc) · 20.9 KB
/
curation_calculator.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-107512713-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', 'UA-107512713-1');
</script>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="img/favicon_no_smile_32px-high.ico" type="image/x-icon">
<meta property="og:title" content="Curation Reward Estimator">
<meta property="og:description" content="Enter a Steem account name and a link to a post or comment to estimate the curation rewards that will be received!">
<meta property="og:image" content="https://i.imgur.com/t0Gk94V.jpg">
<meta property="og:url" content="http://www.steembottracker.com">
<title>Curation Reward Estimator</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Import google fonts - Heading first/ text second -->
<link href='https://fonts.googleapis.com/css?family=Quattrocento+Sans:400,700' rel='stylesheet' type='text/css'>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="scripts/bootstrap-slider.min.js"></script>
<script src="https://cdn.steemjs.com/lib/latest/steem.min.js"></script>
<script src="scripts/sc2.min.js"></script>
<script src="scripts/utils.js?v=5"></script>
<script type="text/javascript">
steem.api.setOptions({ url: 'https://api.steemit.com' });
updateSteemVariables();
</script>
<!-- Dynamic admin theme -->
<link rel="stylesheet" href="css/icons.css">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/plugins.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/custom.css">
<style type="text/css">
.slider.slider-horizontal { width: 80%; }
</style>
</head>
<body>
<div id="header" class="page-navbar header-fixed">
<nav class="navbar navbar-default" style="margin-bottom: 0;">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="bottracker.html" class="navbar-brand">
<img alt="Steem Post Promoter" src="img/header_logo.png" height="44" style="margin-top: -10px;">
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-android mr10"></i>
Voting Bots <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="bottracker.html#bid"><i class="l-basic-hammer mr10"></i> Bid-Based Voting Bots</a></li>
<li><a href="bottracker.html#paid"><i class="l-banknote mr10"></i> Promotion Services</a></li>
<li><a href="bottracker.html#free"><i class="fa fa-android mr10"></i> Other Bots</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-wrench mr10"></i>
Tools <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="config.html"><i class="fa fa-code mr10"></i> Bot Owner Config</a></li>
<li><a href="curation_calculator.html"><i class="fa fa-calculator mr10"></i> Curation Estimator</a></li>
<li><a href="delegation.html"><i class="fa fa-retweet mr10"></i> Delegation Manager</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown" id="user_info">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span id="login_info"></span>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="#" id="btn_logout"><i class="fa fa-calculator mr10"></i> Log Out</a></li>
</ul>
</li>
<li id="btn_login">
<button type="button" class="btn btn-default navbar-btn" onclick="window.location.href=sc2.getLoginURL();">Log in</button>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"> Curation Reward Estimator</h4>
</div>
<div class="panel-body">
<h4>Enter a Steem account name and a link to a post or comment below to estimate the curation rewards that will be received!</h4>
<form class="form-horizontal">
<div class="form-group">
<label class="col-lg-2 col-md-3 control-label" for="account_name">Your Account Name</label>
<div class="col-lg-10 col-md-9">
<div class="input-group">
<span class="input-group-addon">@</span>
<input type="text" class="form-control" id="account_name" placeholder="Account Name">
<span id="account_ok" class="fa fa-check validation-icon-ok color-green" aria-hidden="true" style="display: none;"></span>
<span id="account_bad" class="fa fa-times validation-icon-error color-red" aria-hidden="true" style="display: none;"></span>
</div>
</div>
</div><!-- End .form-group -->
<div class="form-group">
<label class="col-lg-2 col-md-3 control-label" for="post_link" >Post/Comment Link</label>
<div class="col-lg-10 col-md-9">
<input type="text" class="form-control" id="post_link" placeholder="Post/Comment Link">
<span id="post_ok" class="fa fa-check validation-icon-ok post-icon color-green" aria-hidden="true" style="display: none;"></span>
<span id="post_bad" class="fa fa-times validation-icon-error post-icon color-red" aria-hidden="true" style="display: none;"></span>
</div>
</div><!-- End .form-group -->
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" id="btn_submit" class="btn btn-default" onclick="checkAccount();checkPost();document.location.href='#result';">Estimate Curation Rewards</button>
</div>
</div>
</form>
</div>
</div>
<div class="bs-callout bs-callout-info fade in">
<h4>Vote for Witness!</h4>
<p>Help support me and the bot tracker by voting for @yabapmatt for Steem witness! To vote, click the button below or go to <a href="https://steemit.com/~witnesses" target="_blank">https://steemit.com/~witnesses</a> and find @yabapmatt in the list and click the upvote icon. Thank you!</p>
<button class="btn btn-success btn-lg" onclick="window.open('https://v2.steemconnect.com/sign/account-witness-vote?witness=yabapmatt&approve=1');">Vote for @yabapmatt!</button>
</div>
<div id="result" class="well white-bg" style="display: none;"><a name="result"></a>
<dl class="dl-horizontal">
<dt>Post Title:</dt>
<dd><span id="post_title"></span></dd>
<dt>Vote Status:</dt>
<dd><span id="vote_status"></span></dd>
<dt>Vote Value:</dt>
<dd><span id="vote_value"></span></dd>
<dt>Previous Votes Value: <span class="glyphicon glyphicon-info-sign" aria-hidden="true" data-toggle="tooltip" data-placement="top" title="This shows the total value of the votes cast on this post before yours. Curation rewards are heavily dependent on the value of votes cast before yours."></span></dt>
<dd><span id="prev_vote_value"></span></dd>
<dt>Expected Total Payout: <span class="glyphicon glyphicon-info-sign" aria-hidden="true" data-toggle="tooltip" data-placement="top" title="Use this slider to see what the curation reward will be for different total payout amounts for the post."></span></dt>
<dd>
<div id="reward_slider_group" style="display: none;">
<div><b id="slider_min_payout"></b> <input id="post_total_slider" type="text" class="span2" value="" data-slider-min="0" data-slider-max="2000" data-slider-step="1" data-slider-value="100"/> <b id="slider_max_payout">$2,000</b></div>
</div>
<span id="total_payout"></span>
</dd>
</dl>
<div class="alert alert-success" style="text-align: center;">
<h4>Estimated Curation Reward <span class="glyphicon glyphicon-info-sign" aria-hidden="true" data-toggle="tooltip" data-placement="top" title="This shows the expected amount of STEEM POWER / SBD you will receive as a curation reward. This is just an estimation and may vary once the post pays out."></span></h4>
<h3>
<span id="curation_sbd"></span> / <span id="curation_steem"></span>
</h3>
</div>
<div style="display: none;" id="pre_30_note" class="alert alert-warning"></div>
</div>
</div>
<div id="footer" class="clearfix white-bg"><!-- Start #footer -->
<p class="pull-left">
Copyrights © 2017 <a href="http://www.steemit.com/@yabapmatt" class="color-blue strong" target="_blank">Yabapmatt</a>. All rights reserved.
</p>
<p class="pull-right">
Logo by <a href="http://www.steemit.com/@creativista" class="color-blue strong" target="_blank">Creativista</a> |
Bootstrap theme by <a href="http://www.steemit.com/@suggeelson" class="color-blue strong" target="_blank">SuggeElson</a>
</p>
</div><!-- End #footer -->
<script type="text/javascript">
const FULL_CURATION_TIME = 30 * 60 * 1000;
const CURATION_RATE = 0.25;
var data = {};
function loadAccount(cb) {
steem.api.getAccounts([$('#account_name').val()], function(err, result) {
data.account = result[0];
cb();
});
}
function loadPost(cb) {
var link = $('#post_link').val();
var permLink = link.substr(link.lastIndexOf('/') + 1);
var author = link.substring(link.lastIndexOf('@') + 1, link.lastIndexOf('/'));
steem.api.getContent(author, permLink, function (err, result) {
if (!err && result && result.id > 0) {
data.post = result;
}
cb();
});
}
function checkPost() {
loadPost(function () {
var ok = $('#post_ok');
var bad = $('#post_bad');
ok.hide();
bad.hide();
if (data.post) {
ok.show();
if (data.account && data.account.name)
calculate();
} else
bad.show();
});
}
function checkAccount() {
loadAccount(function () {
var ok = $('#account_ok');
var bad = $('#account_bad');
ok.hide();
bad.hide();
if (data.account && data.account.name) {
ok.show();
if (data.post)
calculate();
} else
bad.show();
});
}
$('#post_link').focusout(function (e) { checkPost(); });
$('#account_name').focusout(function (e) { checkAccount(); });
$(function () { $('[data-toggle="tooltip"]').tooltip() });
function rSharesToSBD(rshares) {
return rshares * rewardBalance / recentClaims * steemPrice;
}
function calculate() {
data.rshares_before = 0;
data.rshares_vote = 0;
data.rshares_total = 0;
data.total_vote_weight = 0;
data.pre_30_min_pct = 0;
data.account_vote = null;
data.beneficiary_pct = 0;
if(data.post.beneficiaries && data.post.beneficiaries.length > 0)
{
for(var i = 0; i < data.post.beneficiaries.length; i++) {
var b = data.post.beneficiaries[i];
data.beneficiary_pct += parseInt(b.weight);
}
}
data.beneficiary_pct = (1 - data.beneficiary_pct / 10000);
var votes = data.post.active_votes;
votes.sort(function(a, b) { return new Date(a.time + 'Z') - new Date(b.time + 'Z'); });
var created = new Date(data.post.created + 'Z');
data.post_paid_out = (new Date() - created) > (7 * 24 * 60 * 60 * 1000);
for(var i = 0; i < votes.length; i++) {
var vote = votes[i];
var vote_time = new Date(vote.time + 'Z');
var rshares = parseInt(vote.rshares);
var max_weight = approx_sqrt(data.rshares_total + rshares) - approx_sqrt(data.rshares_total);
vote.rshares_before = data.rshares_total;
vote.pre_30_min_pct = Math.min(vote_time - created, FULL_CURATION_TIME) / FULL_CURATION_TIME;
if(vote.voter == data.account.name) {
data.pre_30_min_pct = Math.min(vote_time - created, FULL_CURATION_TIME) / FULL_CURATION_TIME;
data.rshares_vote = rshares;
data.weight_vote = vote.weight;
data.account_vote = vote;
}
if(data.rshares_vote == 0)
data.rshares_before += rshares;
data.rshares_total += rshares;
if(vote.weight > 0)
data.total_vote_weight += max_weight;
//console.log(vote.voter + ' - rShares: ' + rshares.formatMoney(0) + ', value: ' + rSharesToSBD(rshares).formatMoney(3) + ', before: ' + (data.rshares_vote == 0) + ', author pct: ' + Math.min(vote_time - created, FULL_CURATION_TIME) / FULL_CURATION_TIME);
}
if (data.post_paid_out) {
$('#reward_slider_group').hide();
} else {
var pending_payout = Math.ceil(parseFloat(data.post.pending_payout_value) + ((data.rshares_vote == 0) ? getVoteValue(100, data.account) : 0));
post_slider.slider('setAttribute', 'min', pending_payout);
post_slider.slider('setValue', pending_payout);
$('#slider_min_payout').text('$' + pending_payout);
$('#reward_slider_group').show();
// If the account has not already voted, assume they vote right now at full power
if (data.rshares_vote == 0) {
data.rshares_vote = getVoteRShares(100, data.account);
data.pre_30_min_pct = Math.min(new Date() - created, FULL_CURATION_TIME) / FULL_CURATION_TIME;
data.weight_vote = Math.round((approx_sqrt(data.rshares_total + data.rshares_vote) - approx_sqrt(data.rshares_total)) * data.pre_30_min_pct);
}
}
showRewards();
}
var post_slider = $('#post_total_slider').slider({
formatter: function(value) {
return 'Total Post Rewards: $' + value;
}
});
$('#post_total_slider').on("slide", function (e) {
if (data.rshares_vote > 0)
showRewards();
});
function totalCuration() {
var rshares = 0;
for(var i = 0; i < data.post.active_votes.length; i++) {
var vote = data.post.active_votes[i];
vote.curation_rshares = (Math.sqrt(vote.rshares_before * CURATION_RATE + parseInt(vote.rshares) * CURATION_RATE) - Math.sqrt(vote.rshares_before * CURATION_RATE)) * Math.sqrt(data.rshares_total * CURATION_RATE) * vote.pre_30_min_pct * data.beneficiary_pct;
rshares += vote.curation_rshares;
vote.curation_steem = vote.curation_rshares * rewardBalance / recentClaims;
vote.matt_weight = (Math.sqrt(vote.rshares_before + parseInt(vote.rshares)) - Math.sqrt(vote.rshares_before)) * vote.pre_30_min_pct;
}
return rshares * rewardBalance / recentClaims;
}
function showRewards() {
if(!data.post_paid_out){
data.rshares_total = parseInt($('#post_total_slider').val()) / steemPrice * recentClaims / rewardBalance;
data.total_vote_weight = approx_sqrt(data.rshares_total);
}
var curation_rshares = data.rshares_total * CURATION_RATE * data.weight_vote / data.total_vote_weight;
var curation_steem = curation_rshares * rewardBalance / recentClaims;
var curation_sbd = curation_steem * steemPrice;
$('#post_title').text(data.post.title);
$('#vote_status').text('@' + data.account.name + (data.account_vote ? ' has already voted on this post.' : ' has not voted on this post.'));
$('#total_payout').text(data.post_paid_out ? ('$' + rSharesToSBD(data.rshares_total).formatMoney() + ' (This post has already paid out)') : '');
if(data.account_vote)
$('#vote_value').text('$' + rSharesToSBD(data.account_vote.rshares).formatMoney() + ' (' + (data.account_vote.percent / 100).formatMoney(0) + '%)');
else
$('#vote_value').text('$' + getVoteValue(100, data.account).formatMoney());
$('#prev_vote_value').text('$' + rSharesToSBD(data.rshares_before).formatMoney());
$('#curation_steem').html(curation_steem.formatMoney(3) + ' STEEM POWER');
$('#curation_sbd').text('$' + curation_sbd.formatMoney());
$('#pre_30_note').hide();
var warning = '';
if(data.pre_30_min_pct < 1) {
if(!data.account_vote)
warning = 'NOTE: This post is only ' + (data.pre_30_min_pct * 30).formatMoney(0) + ' minutes old so ' + ((1 - data.pre_30_min_pct) * 100).formatMoney(0) + '% of the curation rewards will go to the author.';
else
warning = 'NOTE: @' + data.account.name + '\'s vote was cast when this post was ' + (data.pre_30_min_pct * 30).formatMoney(0) + ' minutes old so ' + ((1 - data.pre_30_min_pct) * 100).formatMoney(0) + '% of the curation rewards went to the author.';
}
if(warning != '') {
$('#pre_30_note').show();
$('#pre_30_note').text(warning);
}
$('#result').show();
}
// Initialize and try to log in with SteemConnect V2
var token = getURLParameter('access_token') ? getURLParameter('access_token') : localStorage.getItem('access_token');
sc2.init({
baseURL: 'https://v2.steemconnect.com',
app: 'bottracker.app',
accessToken: token,
callbackURL: 'https://steembottracker.com/curation_calculator.html',
scope: ['login', 'vote']
});
var user = null;
sc2.me(function (err, result) {
if (result && !err) {
console.log(result);
user = result.account;
$('#btn_login').hide();
$('#user_info').show();
$('#login_info').text('@' + user.name);
localStorage.setItem('access_token', token);
} else {
$('#btn_login').show();
$('#user_info').hide();
}
});
$('#btn_logout').click(function () {
localStorage.removeItem('access_token');
window.location.href = window.location.pathname;
});
//Functions for Approx SQRT (see https://github.com/steemit/steem/blob/5c787c5baa651858658caa2bd47473846b099c0a/doc/sqrt.md)
function approx_sqrt(x){
if(x == 0) return 0;
msb_x = find_msb(x);
msb_z = msb_x >> 1;
msb_x_bit = shiftleft64(1,msb_x);
msb_z_bit = shiftleft64(1,msb_z);
mantissa_mask = msb_x_bit - 1;
mantissa_x = and64(x,mantissa_mask);
mantissa_z_hi = and64(msb_x,1) ? msb_z_bit : 0;
mantissa_z_lo = shiftright64(mantissa_x , msb_x - msb_z);
mantissa_z = shiftright64(or64(mantissa_z_hi , mantissa_z_lo) , 1);
result = or64(msb_z_bit , mantissa_z);
return result;
}
function find_msb(x){
return Math.floor(Math.log(x)/Math.log(2));
}
function hi_lo(x){
r = {};
r.hi = Math.floor(x / Math.pow(2,32));
r.lo = x % Math.pow(2,32);
return r;
}
function and64(x,y){
x = hi_lo(x);
y = hi_lo(y);
hi = x.hi & y.hi;
lo = x.lo & y.lo;
return hi*Math.pow(2,32) + lo;
}
function or64(x,y){
x = hi_lo(x);
y = hi_lo(y);
hi = x.hi | y.hi;
lo = x.lo | y.lo;
return hi*Math.pow(2,32) + lo;
}
function shiftleft64(x,y){
x = hi_lo(x);
hi = x.hi * Math.pow(2,y);
lo = x.lo * Math.pow(2,y);
return hi*Math.pow(2,32) + lo;
}
function shiftright64(x,y){
x = hi_lo(x);
hi = Math.floor(x.hi / Math.pow(2,y));
aux = x.hi % Math.pow(2,y);
lo = Math.floor(x.lo / Math.pow(2,y)) + aux * Math.pow(2,32-y);
return hi*Math.pow(2,32) + lo;
}
</script>
</body>
</html>