Skip to content

Instantly share code, notes, and snippets.

@jinhwanlazy
Last active September 6, 2017 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jinhwanlazy/569eae4f719676468652ec2e175e94c7 to your computer and use it in GitHub Desktop.
Save jinhwanlazy/569eae4f719676468652ec2e175e94c7 to your computer and use it in GitHub Desktop.
Boscoin rewards calculator
"""
Calculates expected number of rewards by operating a BOScoin node.
Note that this is speculation, since we don't know how many frozen units/nodes
will be until genesis. Also note that this script is not applying increasing
number of total supply. However, roughly saying, rewards will not be changed
while every node operators, frozen coin holders try to reinvest all their rewards.
Becasue rewards are distributed by shares.
"""
class RewardCalculator:
def __init__(self, initial_rewards, decrease_rate, decrease_cycle, end):
"""
Args:
initial_rewards: rewords at first year. 18 for confirmation rewards,
and 5400 for every 720 blocks for freezing rewards
decrease_rate: rewards decreases every once a year. 0.0632 for
confirmation rewards, 0.05 for freezing rewards
decrease_cycle: both confirmation and freezing rewards decrease
every 6310000 blocks. It's roughly a year.
end: The block number where the reward ends
"""
self.initial_rewards = initial_rewards
self.decrease_rate = decrease_rate
self.decrease_cycle = decrease_cycle
self.end = end
def sum(self, my_frozen, total_frozen, block_start, block_end):
""" sums up rewards
Args:
my_frozen: Number of frozen coins of mine
total_frozen: Total number of frozen coin along the network
block_start: Block number where your node/freezing started
block_start: Block number where your node/freezing ended
"""
block_start = max(0, min(block_start, self.end))
block_end = max(0, min(block_end, self.end))
assert (block_start <= block_end)
start_year = block_start // self.decrease_cycle
end_year = block_end // self.decrease_cycle
if (start_year == end_year):
return self.initial_rewards * \
(1 - self.decrease_rate) ** start_year * \
(block_end - block_start) * my_frozen / total_frozen
return (self.sum(my_frozen, total_frozen, block_start,
(start_year+1) * self.decrease_cycle-1) +
self.sum(my_frozen, total_frozen,
(start_year+1) * self.decrease_cycle, block_end))
def expect_first_year_reward(my_frozen, node_ratio=0.3, frozen_ratio=0.6, year=1):
""" Expect node operating reward of the first years
Args:
my_bos: Number of frozen Bos in my node
node_ratio: Proportion of frozen coins in nodes along the network
frozen_ratio: Proportion of total frozen coins including frozen coins of nodes
"""
blocks_per_year = 6310000
initial_supply = 500000000
node_frozen = node_ratio * initial_supply
total_frozen = frozen_ratio * initial_supply
confirm_reward = RewardCalculator(18, 0.0631, blocks_per_year, 128 * blocks_per_year)
freezing_reward = RewardCalculator(5400 / 720, 0.05, blocks_per_year, 59 * blocks_per_year)
return confirm_reward.sum(my_frozen, node_frozen, 0, blocks_per_year * year) + \
freezing_reward.sum(my_frozen, total_frozen, 0, blocks_per_year * year)
if __name__ == "__main__":
print(expect_first_year_reward(80000, 0.3, 0.6))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment