Beem 0.19.55 - 3 new functions for SBD to rshares/vote_pct calculations

@flugschwein · 2018-09-09 09:08 · steempeak

Repository

https://github.com/holgern/beem

New Features

  • What feature(s) did you add? I added 3 new functions. 2 of them are added to the beem.steem module, and 1 is added to beem.account. These functions are: sbd_to_rshares, a function to calculate the number of rshares that have an (estimated) value of x SBD, where x is a parameter given to the function. The second function is sbd_to_vote_pct. This can be used to calculate the needed weight to reach an upvote value of x SBD. The third function, get_vote_pct_for_SBD, is used nearly exactly like sbd_to_vote_pct, but is easier to use if you have an Account object. All these changes have been merged into the main beem repo in the Pull Request 76.
  1. sbd_to_rshares This is a function for calculating the number of rshares that currently are worth the number of SBD provided as a parameter to the function. The other parameters are not_broadcasted_vote and precision_iterations. not_broadcasted_vote slightly modifies the calculation so you'll get the number of rshares in return, that are needed to get the desired SBD value if the rshares need to get added to the recent_claims first. The impact is very small if your SBD number is small, but if it get's higher, the impact will get noticeable. The precision_iterations is not needed if not_broadcasted_vote is not True. The higher the number, the higher the precision of the calculation tweak by not_broadcasted_vote, but also the higher the computational effort needed. I built in a rough automatical assignement, so no need to modify this, if you don't really know what you're doing. If you want more information about this function, go read the documentation, or read the source code of this function.

  2. sbd_to_vote_pct sbd_to_vote_pct works very similar to rshares_to_vote_pct, as it returns the required voting percentage for acquiring the given number of SBD in vote value. Besides the number of SBD, you need to provide either a vests, or a SP value, that should be used for the calculation. All the other values are not mandatory, and most of the time you won't need to use them. You can edit voting_power to simulate a specific level of voting power, and you can turn off the not_broadcasted_vote calculation tweak, but most of the time you probably won't need that. If you want more information about this function, go read the documentation, or read the source code of this function.

  3. get_vote_pct_for_SBD Works very similar to #2, sbd_to_vote_pct, but since it's part of the account module, it doesn't need to get SP or vests provided, and can just take that data from the account. If you want more information about this function, go read the documentation, or read the source code of this function.

  • How did you implement it/them? For my implementation of the sbd_to_rshares function without the not_broadcasted_vote set to True, I just needed to divide the amount of SBD through the sbd per rshares which you can easily get with the get_sbd_per_rshares function of the beem.steem module. When the not_broadcasted_vote is False, the calculation is way more complicated. First, I get an estimation of what the return will be by executing sbd_to_rshares with not_broadcasted_vote set to False. Then I iterate through a for loop x times, where x is the precision_iterations. In each of these iterations, the earlier estimation gets further precision through dividing the amount of SBD through the sbd per rshares, but with adding the rshares of the previous iteration to the recent_claims. That way the calculation gets very precise depending on the number of iterations (and the number of SBDs. The higher, the more iterations are needed for the same level of precision). I think there is a way to get the result of the calculation with also a lot of precision, but without needing these iterations, but I haven't found it yet.

sbd_to_vote_pct and get_vote_pct_for_SBD are pretty simple code wise. For the first, I just use sbd_to_rshares to get the rshares, and then rshares_to_vote_pct does the remaining work. For get_vote_pct_for_SBD, it just calls the sbd_to_vote_pct with the current voting power and steem power the account has. For sbd_to_rshares and get_vote_pct_for_SBD I also made unit tests.

I also fixed some documentation errors, and missed stuff in another Pull Request (#78).

I got a lot of help by @crokkon when I was developing these functions. Thanks so much! I will set him as 20% beneficiary for this post

GitHub Account

https://github.com/flugschwein

#utopian-io #development #beem #steemdev #python
Payout: 0.000 HBD
Votes: 73
More interactions (upvote, reblog, reply) coming soon.