How to calculate 100 vote worth

in #utopian-io7 years ago

In this tutorial I will show you how to calculate the 100% vote worth at a given moment. This can vary very quickly depending of available steem, sbd and the market price.

Prerequisites

  • Get account info
    steem.api.getAccounts Retrieves the related data for the account being query, use the position 0 as this returns an array of objects, you can also query multiple accounts at the same time like ['acc1','acc2'] and so on. Make sure to use the correct data to the account you want to calculate vote worth.
  • Get global info
    steem.api.getDynamicGlobalProperties retrieves data regarding the total vesting fund and vesting shares, required for steem formatter and also for vote calculation.
  • Get reward funds
    steem.api.getRewardFund the available data for the current rewards pool
  • Get current median history price
    steem.api.getCurrentMedianHistoryPrice the historical average/value of the STEEM and SBD rate.

Process


Once you have the account information and also the global information, calculated the overall vests for the account, make sure to take out the delegated ones. Calculate the current voting power calculating the difference from the last vote performed with the current time. Use steem.formatter.vestToSteem to get the human readable for the steem power.

Result


Try running the script, yuo can change the username to calculate different accounts 100% vote worth.
node vote_value.js
For @raserrano
Selection_006.png

Verification


Selection_009.png
For @tuanis
Selection_007.png

Verification


Selection_008.png

The code


Selection_004.png
Selection_005.png

Code text

var steem = require('steem'),
wait = require('wait.for');
var vote = 0;
var sp = 0;
var vp = 0;
steem.config.set('websocket','wss://steemd.steemitdev.com');
wait.launchFiber(function() {
  var globalData = wait.for(
    steem.api.getDynamicGlobalProperties
  );
  var accounts = wait.for(
    steem.api.getAccounts,
    ['tuanis']
  );
  var data = wait.for(
    steem.api.getRewardFund,
    'post'
  );

  var vestingSharesParts = accounts[0].vesting_shares.split(' ');
  var receivedSharesParts = accounts[0].received_vesting_shares.split(' ');
  var delegatedSharesParts = accounts[0].delegated_vesting_shares.split(' ');

  var vests = (
      parseFloat(vestingSharesParts) + 
      parseFloat(receivedSharesParts)
    ) - (parseFloat(delegatedSharesParts));
  console.log('Vests: ' + vests);
  var then = new Date(accounts[0].last_vote_time);
  var now = new Date();
  var seconds_since_last_vote = (now - then) / 1000;
  vp = (seconds_since_last_vote * 10000 / 86400 / 5) + 
    accounts[0].voting_power;
  console.log('Voting power is: ' + vp);

  sp = steem.formatter.vestToSteem(
    vests,
    parseFloat(globalData.total_vesting_shares),
    parseFloat(globalData.total_vesting_fund_steem) 
  );
  console.log('Steem power is: ' + sp);
  // Saving the data
  var m = parseInt(100 * vp * (100 * 100) / 10000);
  m = parseInt((m + 49) / 50);
  var i = parseFloat(data.reward_balance.replace(' STEEM', '')) /
    parseFloat(data.recent_claims);
  var sbd_base = wait.for(
    steem.api.getCurrentMedianHistoryPrice
  );
  var o = parseFloat(sbd_base.base.replace(' SBD', '')) /
    parseFloat(sbd_base.quote.replace(' STEEM', ''));
  var a = globalData.total_vesting_fund_steem.replace(' STEEM', '') /
    globalData.total_vesting_shares.replace(' VESTS', '');
  var r = sp / a;
  vote = parseInt(r * m * 100) * i * o;
  vote = vote /100;

  console.log('Vote value: ' + vote.toFixed(2));
  process.exit();
});



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for this as it is probably one of the only tutorials that actually shows working code. If possible could you please explain to me the m variable and why you did that way, specifically the +49/50 that is doing my head in. the 100*100 I believe is getting the vest but I just can't seem to see why the +49/50 ... Is it maybe dividing for 5 days regen? Any help appreciated thanx.

!tip 0.2

I'm glad you found it useful, so basically the idea is that the Regen rate is 2% right?, Every 2.4 hour's or 20% every day, that's a 98/100 rate which can be reduced to 49/50. I hope I could explain it clear. I would need to look for the GitHub link of that specific part but it's been quite a while since I code it lol

Posted using Partiko Android

That makes perfect sense thank you, did you choose to go about it in the way you did due to some large integer issues. I am not sure about js limitations but the others I have seem tend to use a bigInt library and your code handles the numbers perfect without the need... But as for the main thing, thank you that explains it. Now I can stop punching my pc.

!tip 0.5

🎁 Hi @raserrano! You have received 0.5 STEEM tip from @penderis!

Check out @penderis blog here and follow if you like the content :)

Sending tips with @tipU - how to guide :)

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Qurator
Your Quality Content Curator
This post has been upvoted and given the stamp of authenticity by @qurator. To join the quality content creators and receive daily upvotes click here for more info.

Qurator's exclusive support bot is now live. For more info click HERE or send some SBD and your link to @qustodian to get even more support.

Hey @raserrano I am @utopian-io. I have just upvoted you!

Achievements

  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

🎁 Hi @raserrano! You have received 0.2 STEEM tip from @penderis!

Check out @penderis blog here and follow if you like the content :)

Sending tips with @tipU - how to guide :)

Coin Marketplace

STEEM 0.19
TRX 0.13
JST 0.030
BTC 60191.28
ETH 3302.01
USDT 1.00
SBD 2.36