renamed things to match vocabulary decided by Commons Stack comms team

This commit is contained in:
Andrew Chiw 2020-04-24 17:23:31 +02:00
parent e07fcf5c7d
commit 586aba4176
2 changed files with 32 additions and 26 deletions

View File

@ -2,7 +2,11 @@ from typing import List, Tuple
from abcurve import AugmentedBondingCurve
from datetime import datetime
def unlocked_fraction(day: int, cliff_days: int, halflife_days: float) -> float:
def vesting_curve(day: int, cliff_days: int, halflife_days: float) -> float:
"""
The vesting curve includes the flat cliff, and the halflife curve where tokens are gradually unlocked.
It looks like _/--
"""
return 1 - 0.5**((day - cliff_days)/halflife_days)
def convert_80p_to_cliff_and_halflife(days: int, v_ratio: int = 2) -> Tuple[float, float]:
@ -16,10 +20,10 @@ def convert_80p_to_cliff_and_halflife(days: int, v_ratio: int = 2) -> Tuple[floa
cliff = v_ratio * halflife
return cliff, halflife
def hatch_raise_split_pools(total_hatch_raise, funding_pool_fraction):
def hatch_raise_split_pools(total_hatch_raise, hatch_tribute) -> Tuple[float, float]:
"""Splits the hatch raise between the funding / collateral pool based on the fraction."""
funding_pool = funding_pool_fraction * total_hatch_raise
collateral_pool = total_hatch_raise * (1-funding_pool_fraction)
funding_pool = hatch_tribute * total_hatch_raise
collateral_pool = total_hatch_raise * (1-hatch_tribute)
return funding_pool, collateral_pool
def contributions_to_token_batches(hatcher_contributions: List[int], initial_token_supply: int, vesting_80p_unlocked: int) -> List[float]:
@ -52,18 +56,18 @@ class TokenBatch:
def unlocked(self, day: datetime = datetime.today()) -> float:
if self.hatch_tokens:
days_delta = day - self.creation_date
u = unlocked_fraction(days_delta.days, self.cliff_days, self.halflife_days)
u = vesting_curve(days_delta.days, self.cliff_days, self.halflife_days)
return u if u > 0 else 0
else:
return 1.0
class Organization:
def __init__(self, total_hatch_raise, token_supply, funding_pool_fraction=0.2, exit_tribute=0):
# a fledgling organization starts out in the hatching phase. After the hatch phase ends, money from new investors will only go into the collateral pool.
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.funding_pool_fraction = funding_pool_fraction
self._collateral_pool = (1-funding_pool_fraction) * total_hatch_raise # (1-0.35) -> 0.65 * total_hatch_raise = 65% collateral, 35% funding
self._funding_pool = funding_pool_fraction * total_hatch_raise # 0.35 * total_hatch_raise = 35%
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)
@ -90,13 +94,13 @@ class Organization:
money_returned = dai
if self.exit_tribute:
self._funding_pool += organization.exit_tribute * dai
money_returned = (1-organization.exit_tribute) * dai
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 organization's collateral pool.
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)

View File

@ -3,27 +3,29 @@ import unittest
from datetime import datetime, timedelta
class TestHatch(unittest.TestCase):
def test_unlocked_fraction(self):
self.assertEqual(unlocked_fraction(90, 90, 90), 0) # At Day 90, the cliff has just ended and the vesting curve has begun at 0
self.assertEqual(unlocked_fraction(180, 90, 90), 0.5) # At Day 180, the cliff has ended and we are in the vesting curve, whose half-life is 90 as well, so at 180 we should get 0.5.
self.assertEqual(unlocked_fraction(270, 90, 90), 0.75) # At Day 270, 2 half lives of the vesting curve have passed - 0.75 of tokens should be unlocked.
self.assertLess(unlocked_fraction(89, 90, 90), 0) # At Day 270, 2 half lives of the vesting curve have passed - 0.75 of tokens should be unlocked.
def test_vesting_curve(self):
self.assertEqual(vesting_curve(90, 90, 90), 0) # At Day 90, the cliff has just ended and the vesting curve has begun at 0
self.assertEqual(vesting_curve(180, 90, 90), 0.5) # At Day 180, the cliff has ended and we are in the vesting curve, whose half-life is 90 as well, so at 180 we should get 0.5.
self.assertEqual(vesting_curve(270, 90, 90), 0.75) # At Day 270, 2 half lives of the vesting curve have passed - 0.75 of tokens should be unlocked.
self.assertLess(vesting_curve(89, 90, 90), 0) # At Day 270, 2 half lives of the vesting curve have passed - 0.75 of tokens should be unlocked.
def test_convert_80p_to_halflife(self):
self.assertEqual(convert_80p_to_cliff_and_halflife(90), (41.64807836875666, 20.82403918437833))
class TestSystem(unittest.TestCase):
def test_system(self):
# 3 contributors contribute equally to the foundation of an organization for 6 million tokens.
token_supply_initial = 6e6
hatcher_contributions = [3e3, 3e3, 3e3]
# 100,000 DAI invested for 1,000,000 tokens.
desired_token_price = 0.1
hatcher_contributions = [25000, 25000, 50000]
token_supply_initial = sum(hatcher_contributions) / desired_token_price
token_batches = contributions_to_token_batches(hatcher_contributions, token_supply_initial, 90)
o = Organization(sum(hatcher_contributions), token_supply_initial, funding_pool_fraction=0.3)
self.assertEqual(o._collateral_pool, 6300)
self.assertEqual(o._funding_pool, 2700)
# Because of hatch_tribute, the collateral_pool is 0.7e6. This causes the token's post-hatch price to be 0.14.
o = Commons(sum(hatcher_contributions), token_supply_initial, hatch_tribute=0.3)
self.assertEqual(o._collateral_pool, 70000)
self.assertEqual(o._funding_pool, 30000)
self.assertEqual(o._token_supply, token_supply_initial)
print(o.token_price())
self.assertEqual(o.token_price(), 0.14)
print(o.deposit(100))
print(o.token_price())
print(o._collateral_pool)