Skip to content

Commit

Permalink
Add Python script for calculating Freicoin demurrage parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Friedenbach committed Dec 31, 2013
1 parent 4126484 commit d9c449b
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions contrib/freicoin/demurrage_parameters_arithmetic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python

from __future__ import division

try:
from gmpy2 import mpq as Fraction
except ImportError:
from fractions import Fraction

TOTAL_SUPPLY = 10**16 - 1
EQ_HEIGHT = 161280
TITHE_RATIO = Fraction(4,5)
TITHE_AMOUNT = TOTAL_SUPPLY * TITHE_RATIO / EQ_HEIGHT
DEMURRAGE_RATE = 2**20

def sample_run(subsidy):
def get_block_value(height):
if height < EQ_HEIGHT:
return Fraction(TOTAL_SUPPLY, DEMURRAGE_RATE) + TITHE_AMOUNT + \
Fraction((EQ_HEIGHT - height) * subsidy, EQ_HEIGHT)
else:
return Fraction(TOTAL_SUPPLY, DEMURRAGE_RATE)
total=0
for i in xrange(EQ_HEIGHT):
total = total + get_block_value(i) - Fraction(total, DEMURRAGE_RATE)
return total

print "Performing binary search..."

low,high = 0, TOTAL_SUPPLY
while True:
if (high-low) <= 1:
break
sample = (low+high)//2
result = sample_run(sample)
if result < TOTAL_SUPPLY:
low = sample
else:
high = sample
print(high - low)
initial = low
if sample_run(initial) >= TOTAL_SUPPLY:
initial = initial - 1
print "Tithe amount: %d" % TITHE_AMOUNT
print "Initial subsidy: %d" % initial
print "Initial reward: %d" % (initial + TOTAL_SUPPLY//DEMURRAGE_RATE)
print "Final subsidy: %d" % 0
print "Final reward: %d" % (TOTAL_SUPPLY//DEMURRAGE_RATE)
print "Equilibrium: Block #%d" % EQ_HEIGHT
print "Approx delta: %f" % (initial / EQ_HEIGHT / 100000000)
print "Max coins: %d" % sample_run(initial)

0 comments on commit d9c449b

Please sign in to comment.