diff --git a/bclib.py b/bclib.py new file mode 100644 index 0000000..4e03b3b --- /dev/null +++ b/bclib.py @@ -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 diff --git a/example.py b/example.py new file mode 100644 index 0000000..3f98cfb --- /dev/null +++ b/example.py @@ -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)