Skip to content
Snippets Groups Projects
Commit 3822a14b authored by crokkon's avatar crokkon
Browse files

steem.py: fix missing steem_instance for Amount()

* restructuring `sbd_to_rshares` to avoid redundant function calls and
streamline the calculations
parent abd51c14
No related branches found
No related tags found
No related merge requests found
...@@ -665,35 +665,31 @@ class Steem(object): ...@@ -665,35 +665,31 @@ class Steem(object):
sbd = Amount(sbd, self.sbd_symbol, steem_instance=self) sbd = Amount(sbd, self.sbd_symbol, steem_instance=self)
if sbd['symbol'] != self.sbd_symbol: if sbd['symbol'] != self.sbd_symbol:
raise AssertionError('Should input SBD, not any other asset!') raise AssertionError('Should input SBD, not any other asset!')
reward_pool_sbd = self.get_median_price(use_stored_data=use_stored_data) * Amount(self.get_reward_funds(use_stored_data=use_stored_data)['reward_balance'])
if sbd.amount > reward_pool_sbd.amount:
raise ValueError('Provided more SBD than available in the reward pool.')
# If the vote was already broadcasted we can assume the blockchain values to be true # If the vote was already broadcasted we can assume the blockchain values to be true
if not not_broadcasted_vote: if not not_broadcasted_vote:
return sbd.amount / self.get_sbd_per_rshares(use_stored_data=use_stored_data) return int(sbd.amount / self.get_sbd_per_rshares(use_stored_data=use_stored_data))
# If the vote wasn't broadcasted (yet), we have to calculate the rshares while considering # If the vote wasn't broadcasted (yet), we have to calculate the rshares while considering
# the change our vote is causing to the recent_claims. This is more important for really # the change our vote is causing to the recent_claims. This is more important for really
# big votes which have a significant impact on the recent_claims. # big votes which have a significant impact on the recent_claims.
# Get some data from the blockchain
reward_fund = self.get_reward_funds(use_stored_data=use_stored_data) reward_fund = self.get_reward_funds(use_stored_data=use_stored_data)
reward_balance = Amount(reward_fund["reward_balance"], steem_instance=self).amount
recent_claims = float(reward_fund["recent_claims"])
median_price = self.get_median_price(use_stored_data=use_stored_data) median_price = self.get_median_price(use_stored_data=use_stored_data)
SBD_price = (median_price * Amount(1, self.steem_symbol, steem_instance=self)).amount recent_claims = int(reward_fund["recent_claims"])
reward_balance = Amount(reward_fund["reward_balance"], steem_instance=self)
reward_pool_sbd = median_price * reward_balance
if sbd > reward_pool_sbd:
raise ValueError('Provided more SBD than available in the reward pool.')
# This is the formular we can use to determine the "true" rshares # This is the formula we can use to determine the "true" rshares.
# We get this formular by some math magic using the previous used formulas # We get this formula by some math magic using the previous used formulas
# FundsPerShare = (balance / (claims+newShares))*Price # FundsPerShare = (balance / (claims + newShares)) * Price
# newShares = Amount / FundsPerShare # newShares = amount / FundsPerShare
# We can now resolve both formulas for FundsPerShare and set the formulas to be equal # We can now resolve both formulas for FundsPerShare and set the formulas to be equal
# (balance / (claims+newShares))*Price = Amount / newShares # (balance / (claims + newShares)) * price = amount / newShares
# Now we resolve for newShares resulting in: # Now we resolve for newShares resulting in:
# newShares = = claims * amount / (balance*price -amount) # newShares = claims * amount / (balance * price - amount)
rshares = recent_claims * sbd.amount / ((reward_balance * SBD_price) - sbd.amount) rshares = recent_claims * sbd.amount / ((reward_balance.amount * float(median_price)) - sbd.amount)
return int(rshares) return int(rshares)
def rshares_to_vote_pct(self, rshares, steem_power=None, vests=None, voting_power=STEEM_100_PERCENT, use_stored_data=True): def rshares_to_vote_pct(self, rshares, steem_power=None, vests=None, voting_power=STEEM_100_PERCENT, use_stored_data=True):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment