erc20-demurrage-token

ERC20 token with redistributed continual demurrage
Info | Log | Files | Refs | README

sim_noredistribute.py (3047B)


      1 # standard imports
      2 import logging
      3 
      4 # local imports
      5 from erc20_demurrage_token import DemurrageTokenSettings
      6 from erc20_demurrage_token.sim import DemurrageTokenSimulation
      7 
      8 logging.basicConfig(level=logging.INFO)
      9 logg = logging.getLogger()
     10 
     11 decay_per_minute = 0.00000050105908373373 # equals approx 2% per month
     12 
     13 # parameters for simulation object
     14 settings = DemurrageTokenSettings()
     15 settings.name = 'Simulated Demurrage Token'
     16 settings.symbol = 'SIM'
     17 settings.decimals = 6
     18 settings.demurrage_level = int(decay_per_minute*(10**38))
     19 #settings.period_minutes = 1 # 1 week in minutes
     20 settings.period_minutes = 60*24*7
     21 chain = 'evm:foochain:42'
     22 cap = (10 ** 6) * (10 ** 12)
     23 #cap = 0
     24 
     25 # instantiate simulation
     26 sim = DemurrageTokenSimulation(chain, settings, redistribute=False, cap=cap, actors=10)
     27 
     28 # name the usual suspects
     29 alice = sim.actors[0]
     30 bob = sim.actors[1]
     31 carol = sim.actors[2]
     32 
     33 # mint and transfer (every single action advances one block, and one second in time)
     34 sim.mint(alice, sim.from_units(100)) # 10000000 tokens
     35 sim.mint(bob, sim.from_units(100))
     36 sim.transfer(alice, carol, sim.from_units(50))
     37 
     38 # check that balances have been updated
     39 #assert sim.balance(alice) == sim.from_units(50)
     40 #assert sim.balance(bob) == sim.from_units(100)
     41 #assert sim.balance(carol) == sim.from_units(50)
     42 
     43 # advance to next redistribution period
     44 sim.next()
     45 
     46 # inspect balances
     47 print('alice balance: demurraged {:>9d} base {:>9d}'.format(sim.balance(alice), sim.balance(alice, base=True)))
     48 print('bob balance:   demurraged {:>9d} base {:>9d}'.format(sim.balance(bob), sim.balance(bob, base=True)))
     49 print('carol balance: demurraged {:>9d} base {:>9d}'.format(sim.balance(carol), sim.balance(carol, base=True)))
     50 print('sink balance:  demurraged {:>9d} base {:>9d}'.format(sim.balance(sim.sink_address), sim.balance(sim.sink_address, base=True)))
     51 
     52 # get times
     53 minutes = sim.get_minutes()
     54 timestamp = sim.get_now()
     55 start = sim.get_start()
     56 period = sim.get_period()
     57 print('start {} now {} period {} minutes passed {}'.format(start, timestamp, period, minutes))
     58 
     59 
     60 contract_demurrage = 1 - sim.get_demurrage()    # demurrage in percent (float)
     61 frontend_demurrage = 1.0 - ((1 - decay_per_minute) ** minutes)   # corresponding demurrage modifier (float)
     62 demurrage_delta = contract_demurrage - frontend_demurrage      # difference between demurrage in contract and demurrage calculated in frontend
     63 
     64 alice_checksum = 50000000 - (50000000 * frontend_demurrage) + (200000000 * frontend_demurrage) # alice's balance calculated with frontend demurrage
     65 #print("""alice frontend balance {}
     66 print("""alice contract balance {}
     67 frontend demurrage {:.38f}
     68 contract demurrage {:.38f}
     69 demurrage delta {:.38f}""".format(
     70     alice_checksum,
     71     sim.balance(alice),
     72     frontend_demurrage,
     73     contract_demurrage,
     74     demurrage_delta),
     75 )
     76 
     77 balance_sum = sim.balance(alice) + sim.balance(bob) + sim.balance(carol) + sim.balance(sim.sink_address)
     78 supply = sim.get_supply()
     79 print('sum of contract demurraged balances {}'.format(balance_sum))
     80 print('total token supply {}'.format(supply))