Calculating the USD Vote Value for a Hive account

in HiveDevs3 years ago (edited)

A few days ago I was writing a seemingly simple script for the @Rabona Curation Program. The script was supposed to simply calculate the USD vote values of all the Curation Followers, and sum them up to find out what is the total USD value of the Curation Trail. Simple enough, right?

Well, easier said than done. What actually happened is that I have been somewhat struggling to achieve that, for multiple reasons:

  1. Lack of proper documentation. I think the entire Hive ecosystem lacks a proper and comprehensive documentation, especially the technical documentation. Often times a developer is on their own, with some bits of information here, maybe some code samples there, but nothing thorough.

    I don't want to complain. I work as a Software Engineer myself and I know it takes crazy amount of work to do everything right: develop, maintain, document.

    Hopefully this situation will improve in the future, and I will try to do my part as well—if I only can! This post will hopefully be a brick in this wall :)

  2. Outdated libraries. I wanted to calculate the USD vote value in a Python app, so I immediately though that maybe the beem library has a simple method to do it. And it does, but these methods (beem.account.Account.get_voting_value and beem.account.Account.get_voting_value_SBD) seem to be outdated and do not return proper values.

    It is not a secret that the beem library is not the most maintained one. The original developer no longer actively works on it, although there have been some updates pushed by the community. But I don't want to focus on beem itself, but rather treat it as an example of a bigger problem. There are many Hive-related libraries written for various programming languages and solving various problems, which are abandoned and no longer maintained. Relying on them is risky at best.

These problems mean that it is much harder for a developer to start building something new for the Hive blockchain, as they have to do a lot of digging and rummaging, and rely on very low-level solutions (which are hard to maintain and take more time to implement).

I feel that my struggle with calculating the vote value partly came from these exact issues that I described. While searching through Hive to find whether someone had similar issues and maybe shared a solution of some sort, I stumbled upon a post from almost a half year ago written by @cryptosharon, describing the very same struggle that I had.

I left a comment under that post just to share my difficulties, but later I managed to finally implement the estimation of the USD vote value. I promised to share my solution, which I have rewritten from Python to JavaScript.


* * *

The code is fairly simple and it follows the formula available within the Official Hive.io documentation. As far as I understand it, it users the current reward fund and user's VESTS to calculate how much of that fund the user is able to direct towards a post by upvoting. Then this tiny bit of the reward fund is converted from the native cryptocurrencies (HIVE and HBD) into the USD price.

I cross-checked the results of this script with platforms like hivestats.io and it seems to work. If you find any issues with it, though, or have any questions—feel free to ask!

View the Gist with the JavaScript code to calculate USD vote value for any Hive user

Sort:  

You're very right about the documentation problem. I've also noticed it! Something I've done on my own blog and that I think I've somewhat succeeded at is to format my titles in a way that will be easy to find on Google for someone in doubt.

I would suggest, for example, that you add Hive to your title. Like this:

Calculating the USD Vote Value for a Hive account

and also maybe changing the wording? I'm not sure if it will be better. I'm not a native speaker but i would probably google it like this:

calculate hive vote value

or

calculate "hive.io" vote value

I think that due to Hive's decentralized nature, most answers are "documented" on posts. I know that any time I want to share a big chunk of information on Hive, I generally make a full post about it. That way I can find it later, others can find it associated with me, I get money, etc. Making a separate website is just not as profitable.

I think that as long as this decentralized manner of documentation gets indexed properly on search engines, it will be trivial for devs to dev. (But so far it doesn't.)

A good project would be to document Hive in a series of inter-linked posts, and finding posts that already have documentation and linking to them in a systematic manner, like an index. Maybe that would help us solve the issue.

I would suggest, for example, that you add Hive to your title. Like this:

Thanks for the idea! I did update the title. I am not so good at SEO and related topics, unfortunately. But I think it makes sense to care for it, as I found your original post using Google search (I think I entered something like calculcate usd value for a vote on hive blockchain.

That could be good. I think we also need ways to incentivise tech-people to create libraries, projects, as well as document them properly. Remember @utopian-io? I think that was a revolutionary project that could help to solve these kinds of issues. Too bad it failed in the end.

Hi, why is my voting value 0? How do I increase it? Thank you in advance. (If there is some article maybe where it is all explained for complete noobs?)

Hmm, your code seems to give some correct information maybe? It's not the same as the one PeakD and Hive.Blog give tho.

I just voted and it was 0.16, and I just requested the info from your code and the console log result was 0.1979

Vote value: 0.1979061971029384

I also had to modify from console.info to console.log

Anyway, I'm unsure why this inaccuracy happens! PeakD's estimate on my vote size is 0.157 | 0.16

image.png

image.png

I think this discrepancy comes from two things:

  1. Please note that my code by default calculates the Vote Value as if you had 100% Voting Power.

    If you want to check your CURRENT vote value, with the Voting Power that you have at the moment, use getUserVoteValue({ username: 'cryptosharon', fullVotingPower: false }).

  2. As far as I understand, most of the services do not follow the formula from the documentation. The formula clearly specifies to provide the base price from the condenser_api.get_current_median_history_price call:

    Last thing we will need is rate of the get_current_median_history_price, returns median price rate bucket with base element.

    If you check the response from that API call, it is currently base: "0.894 HBD". That's what I use to calculate, but I find that if I provide 1.0 as the base value, and not that value, the estimated values will be much closer to the ones given by services such as PeakD or hivestats.io. I don't know why that is, though, that those services do it differently than it is in the documentation.

Loading...

Congratulations @mciszczon! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):

You distributed more than 9000 upvotes.
Your next target is to reach 10000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out the last post from @hivebuzz:

Hive Power Up Day - May 1st 2022