示例#1
0
 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)
示例#2
0
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)
示例#3
0
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