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

in #utopian-io6 years ago (edited)

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.

  1. 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

Sort:  

Thank you for your contribution. Nice to have these calculations in the beem library and +1 for the unit tests! The only thing I may 'complain' is the inconsistency of the letter cases for SBD in get_vote_pct_for_SBD and sbd_to_vote_pct.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Yeah this kinda bugs me as well, but I just kept to the style depending on the submodule. The only other function in the beem.account module with sbd in it's name has it written in capital letters (see here), and in the beem.steem module sbd is always written lowercase. I just sticked to what already existed so it is an inconsistency trying to keep consistency.
Thanks for your review

Thank you for your review, @justyy!

So far this week you've reviewed 2 contributions. Keep up the good work!

I see You liked this project so much. Good job helping develop beem! The best Steem API right now.

Yes flugs!!!! self flag for the win!

You have a minor misspelling in the following sentence:

The impact is very small if your SBD number is small, but if it get's higher, the impact will get noticable.
It should be noticeable instead of noticable.

I like this bot

Hi @flugschwein!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by Flugschwein from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.

Hey, @flugschwein!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.22
TRX 0.20
JST 0.034
BTC 98504.77
ETH 3362.26
USDT 1.00
SBD 3.06