Skip to content

Instantly share code, notes, and snippets.

@jaekwon
Created June 29, 2017 18:38
Show Gist options
  • Save jaekwon/fdbe2bc79b309e8e54caeac03c1e010b to your computer and use it in GitHub Desktop.
Save jaekwon/fdbe2bc79b309e8e54caeac03c1e010b to your computer and use it in GitHub Desktop.
Bancor simulation
balance = 1.0 # amount of reserve tokens
supply = 1000.0 # amount of smart tokens
crr = 0.001 # arbitrary reserve ratio
def printInfo():
price = computePrice()
print "balance", balance, "supply", supply, "price", price
def computePrice():
return balance / (supply * crr)
print "Initial price", computePrice()
# keep buying
i = 0
while True:
# debug
if i % 10000 == 0:
printInfo()
import time
time.sleep(0.1)
i+=1
# how much to purchase: 1.0 reserve token
purchase = 1.0
price = computePrice()
balance += purchase
supply += purchase / price
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment