Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
eun2ce committed May 30, 2019
1 parent e42982a commit ddaf7a0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
27 changes: 27 additions & 0 deletions bclib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class bancor:
total_supply = 0
reserved_token = 0
price = 0
cw = 0

def __init__(self, token, rate, cw):
bancor.total_supply = token * rate
bancor.reserved_token = (bancor.total_supply * cw)
bancor.price = bancor.reserved_token / (bancor.total_supply * cw)
bancor.cw = cw

@staticmethod
def issue_by_reserve_token(amount):
smart_token_amount = bancor.total_supply * (((1 + (amount / bancor.reserved_token)) ** bancor.cw) -1)
bancor.reserved_token = bancor.reserved_token + amount
bancor.total_supply = bancor.total_supply + smart_token_amount
bancor.price = bancor.reserved_token / (bancor.total_supply * bancor.cw)
return smart_token_amount

@staticmethod
def destroy_by_reserve_token(amount):
smart_token_amount = bancor.reserved_token * (1 - ((1 - (amount / bancor.total_supply)) ** (1/bancor.cw)))
bancor.reserved_token = bancor.reserved_token -smart_token_amount
bancor.total_supply = bancor.total_supply - amount
bancor.price = bancor.reserved_token / (bancor.total_supply * bancor.cw)
return smart_token_amount
8 changes: 8 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from bclib import bancor

bancor_1 = bancor(300000, 1, 0.2)
# @total_supply=300299.40179372387, @reserved_token=60300.0, @price=1.003998003989035, @crr=0.2>
bancor_1.issue_by_reserve_token(300)
bancor_1.issue_by_reserve_token(700)
bancor_1.destroy_by_reserve_token(1302)
bancor_1.issue_by_reserve_token(100)

0 comments on commit ddaf7a0

Please sign in to comment.