Esempio n. 1
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)
Esempio n. 2
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
Esempio n. 3
0
    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)