def test_get_token_supply(self): # R = 1, S0 = 1, V0 = 1.0, kappa = 2 should give this data: # [0 1 2 3 4 5 6 7 8 9] -> [0.0, 1.0, 1.4142135623730951, 1.7320508075688772, 2.0, 2.23606797749979, 2.449489742783178, 2.6457513110645907, 2.8284271247461903, 3.0] abc = AugmentedBondingCurve(1, 1, kappa=2) self.assertEqual(abc.get_token_supply(1), 1) self.assertEqual(abc.get_token_supply(2), 1.4142135623730951)
def test_deposit(self): abc = AugmentedBondingCurve(1, 1, kappa=2) old_current_reserve = 1 old_token_supply = 1 # print(abc) # Deposit 4 million DAI, given that the current reserve pool is 1 million DAI and there are 1 million tokens tokens, realized_price = abc.deposit(4, 1, 1) print("The current price is", realized_price, "and you will get", tokens, "million tokens") self.assertEqual(tokens, 1.2360679774997898) self.assertEqual(realized_price, 3.2360679774997894)
class Commons: def __init__(self, total_hatch_raise, token_supply, hatch_tribute=0.2, exit_tribute=0): # a fledgling commons starts out in the hatching phase. After the hatch phase ends, money from new investors will only go into the collateral pool. # Essentials self.hatch_tribute = hatch_tribute self._collateral_pool = ( 1 - hatch_tribute ) * total_hatch_raise # (1-0.35) -> 0.65 * total_hatch_raise = 65% collateral, 35% funding self._funding_pool = hatch_tribute * total_hatch_raise # 0.35 * total_hatch_raise = 35% self._token_supply = token_supply self._hatch_tokens = token_supply # hatch_tokens keeps track of the number of tokens that were created when hatching, so we can calculate the unlocking of those self.bonding_curve = AugmentedBondingCurve(self._collateral_pool, token_supply) # Options self.exit_tribute = exit_tribute def deposit(self, dai): """ Deposit DAI after the hatch phase. This means all the incoming deposit goes to the collateral pool. """ tokens, realized_price = self.bonding_curve.deposit( dai, self._collateral_pool, self._token_supply) self._token_supply += tokens self._collateral_pool += dai return tokens, realized_price def burn(self, tokens): """ Burn tokens, with/without an exit tribute. """ dai, realized_price = self.bonding_curve.burn(tokens, self._collateral_pool, self._token_supply) self._token_supply -= tokens self._collateral_pool -= dai money_returned = dai if self.exit_tribute: self._funding_pool += commons.exit_tribute * dai money_returned = (1 - commons.exit_tribute) * dai return money_returned, realized_price def token_price(self): """ Query the bonding curve for the current token price, given the size of the commons's collateral pool. """ return self.bonding_curve.get_token_price(self._collateral_pool)
def __init__(self, total_hatch_raise, token_supply, hatch_tribute=0.2, exit_tribute=0): # a fledgling commons starts out in the hatching phase. After the hatch phase ends, money from new investors will only go into the collateral pool. # Essentials self.hatch_tribute = hatch_tribute self._collateral_pool = ( 1 - hatch_tribute ) * total_hatch_raise # (1-0.35) -> 0.65 * total_hatch_raise = 65% collateral, 35% funding self._funding_pool = hatch_tribute * total_hatch_raise # 0.35 * total_hatch_raise = 35% self._token_supply = token_supply self._hatch_tokens = token_supply # hatch_tokens keeps track of the number of tokens that were created when hatching, so we can calculate the unlocking of those self.bonding_curve = AugmentedBondingCurve(self._collateral_pool, token_supply) # Options self.exit_tribute = exit_tribute
class Commons: def __init__(self, total_hatch_raise, token_supply, hatch_tribute=0.2, exit_tribute=0, kappa=2): # a fledgling commons starts out in the hatching phase. After the hatch phase ends, money from new investors will only go into the collateral pool. # Essentials self.hatch_tribute = hatch_tribute # (1-0.35) -> 0.65 * total_hatch_raise = 65% collateral, 35% funding self._collateral_pool = (1 - hatch_tribute) * total_hatch_raise self._funding_pool = hatch_tribute * \ total_hatch_raise # 0.35 * total_hatch_raise = 35% self._token_supply = token_supply # hatch_tokens keeps track of the number of tokens that were created when hatching, so we can calculate the unlocking of those self._hatch_tokens = token_supply self.bonding_curve = AugmentedBondingCurve(self._collateral_pool, token_supply, kappa=kappa) # Options self.exit_tribute = exit_tribute def deposit(self, dai): """ Deposit DAI after the hatch phase. This means all the incoming deposit goes to the collateral pool. """ tokens, realized_price = self.bonding_curve.deposit( dai, self._collateral_pool, self._token_supply) self._token_supply += tokens self._collateral_pool += dai return tokens, realized_price def burn(self, tokens): """ Burn tokens, with/without an exit tribute. """ dai, realized_price = self.bonding_curve.burn(tokens, self._collateral_pool, self._token_supply) self._token_supply -= tokens self._collateral_pool -= dai money_returned = dai if self.exit_tribute: self._funding_pool += self.exit_tribute * dai money_returned = (1 - self.exit_tribute) * dai return money_returned, realized_price def dai_to_tokens(self, dai): """ Given the size of the common's collateral pool, return how many tokens would x DAI buy you. """ price = self.bonding_curve.get_token_price(self._collateral_pool) return dai / price def token_price(self): """ Query the bonding curve for the current token price, given the size of the commons's collateral pool. """ return self.bonding_curve.get_token_price(self._collateral_pool) def spend(self, amount): """ Decreases the Common's funding_pool by amount. Raises an exception if this would make the funding pool negative. """ if self._funding_pool - amount < 0: raise Exception( "{} funds requested but funding pool only has {}".format( amount, self._funding_pool)) self._funding_pool -= amount return
def test_burn(self): abc = AugmentedBondingCurve(1, 1, kappa=2) dai_million_returned, realized_price = abc.burn(0.5, 1, 1) self.assertEqual(dai_million_returned, 0.75) self.assertEqual(realized_price, 1.5)
def test_get_token_price(self): # [0 1 2 3 4 5 6 7 8 9] -> [0.0, 0.02, 0.0282842712474619, 0.034641016151377546, 0.04, 0.044721359549995794, 0.04898979485566356, 0.052915026221291815, 0.0565685424949238, 0.06] abc = AugmentedBondingCurve(1, 1, kappa=2) self.assertEqual(abc.get_token_price(1), 2.0) self.assertEqual(abc.get_token_price(2), 2.8284271247461903)