From f6e1cde7829f05c64f144add58d2bf8cff42b8b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Rose?= Date: Wed, 21 Feb 2018 01:51:21 +0100 Subject: [PATCH] fixed share token calculation and bond redemption -> 100% stability --- basecoin-sim.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/basecoin-sim.py b/basecoin-sim.py index a946099..ff9e2de 100644 --- a/basecoin-sim.py +++ b/basecoin-sim.py @@ -29,7 +29,7 @@ def compute_bond_price(state): def increase_supply(exchange_rate, state): # Number of newly minted coins - supply_delta = int(TOTAL_SUPPLY * (exchange_rate - 1)) + supply_delta = int(state['coin_supply'] * (exchange_rate - 1)) state['coin_supply'] += supply_delta # Pay bonds @@ -37,21 +37,21 @@ def increase_supply(exchange_rate, state): next_bond_tuple = state['bond_queue'].pop(0) t, amount = next_bond_tuple if amount > supply_delta: - supply_delta = 0 state['bond_queue'].insert(0, (t, amount - supply_delta)) + supply_delta = 0 else: supply_delta -= amount # Pay dividends to shareholders if supply_delta > 0: - state['shareholder_coins'] = supply_delta + state['shareholder_coins'] += supply_delta return state def decrease_supply(exchange_rate, state): # Number of coins to auction/burn - supply_delta = int(TOTAL_SUPPLY * (1 - exchange_rate)) + supply_delta = int(state['coin_supply'] * (1 - exchange_rate)) bond_price = compute_bond_price(state) state['bond_queue'].append((state['t'], int(supply_delta / bond_price))) state['coin_supply'] -= supply_delta