Пример #1
0
def test():
    curve = PriceSupplyCurve(factor=0.0001, base_price=5)
    auction = Auction(factor=0, const=10**3)  # disabled
    beneficiary = Beneficiary(issuance_fraction=0)  # disabled
    ct = Mint(curve, beneficiary, auction)
    ask = ct.ask
    assert ct._sale_cost(1) == ask
    num = 1000
    cost = ct._sale_cost(num)
    assert cost > ask * num
    sold = ct.create(cost)
    xassert(sold, num)
    assert ct.token.supply == sold
    assert ct.token.supply == ct.curve.supply(ct.reserve_value)
    assert ct._skipped_supply == 0, ct._skipped_supply
    assert ct._notional_supply == ct.token.supply
    assert ct.token.accounts[None] == sold
    assert ct._notional_supply == ct.token.supply, (ct._notional_supply, ct.token.supply)
    assert ct.reserve_value == cost
    assert ct.ask > ask
    assert ct.bid < ct.ask, (ct.bid, ct.ask)
    xassert(ct.token.supply, num)
    pcost = ct._purchase_cost(ct.token.supply)
    xassert(pcost, cost)
    received = ct.destroy(num)
    assert ct.token.supply >= 0
    xassert(ct.token.supply, 0)
    assert ct._notional_supply == 0
    assert ct.ask == ask
Пример #2
0
def test_auction():
    curve = PriceSupplyCurve(factor=0.0001, base_price=5)
    auction = Auction(factor=10**5, const=10**3)
    beneficiary = Beneficiary(issuance_fraction=0)
    ct = Mint(curve, beneficiary, auction)
    assert ct.ask > auction.price_surcharge
    ask = ct.ask
    print 'ask', ask
    # xassert(ask, ct.curve.cost(0, 1) / (1 - beneficiary.fraction))
    assert ct._sale_cost(1) == ask

    # buy tokens
    num = 1000
    cost = ct._sale_cost(num)
    assert cost > ask * num
    sold = ct.create(cost)
    xassert(sold, num)
    xassert(num, ct.token.supply)
    print 'bought:', sold, 'at ask:', ask, ' cost:', cost, 'ask after:', ct.ask
    assert ct.token.supply == sold
    assert ct._notional_supply >= ct.token.supply, (ct._notional_supply, ct.token.supply)
    assert ct.reserve_value == cost
    assert ct.ask > auction.price_surcharge
    assert ct.bid < ct.ask, (ct.bid, ct.ask)
    print 'ask', ct.ask, 'bid', ct.bid
    assert ct.ask > ask

    # sell tokens
    num = ct.token.supply
    pcost = ct._purchase_cost(num)
    xassert(pcost, cost)
    received = ct.destroy(num)
    xassert(received, pcost)
    print "sold:", num, "for:", received, "ask:", ct.ask
Пример #3
0
def test_beneficiary():
    curve = PriceSupplyCurve(factor=0.0001, base_price=5)
    auction = Auction(factor=0, const=10**3)  # disabled
    beneficiary = Beneficiary(issuance_fraction=.20)
    ct = Mint(curve, beneficiary, auction)
    ask = ct.ask
    xassert(ask, ct.curve.cost(0, 1) / (1 - beneficiary.fraction))
    assert ct._sale_cost(1) == ask
    # buy
    num = 1000
    cost = ct._sale_cost(num)
    assert cost > ask * num
    sold = ct.create(cost)
    # check
    xassert(sold, num)
    assert ct.token.supply == sold / (1 - beneficiary.fraction)
    assert ct.token.accounts[None] == sold
    assert ct.token.accounts[beneficiary] == ct.token.supply - sold
    num_beneficiary = ct.token.accounts[beneficiary]
    assert ct._notional_supply >= ct.token.supply, (ct._notional_supply, ct.token.supply)
    assert ct.reserve_value == cost
    assert ct.ask > ask
    assert ct.bid < ct.ask, (ct.bid, ct.ask)
    pcost = ct._purchase_cost(ct.token.supply)
    assert pcost == cost

    # sell buyers part
    ask = ct.ask
    pcost = ct._purchase_cost(num)
    received = ct.destroy(num)
    xassert(received, pcost)
    assert ct.token.supply == num_beneficiary
    assert ct.ask < ask

    # sell beneficiary part
    assert num_beneficiary == ct.token.accounts[beneficiary]
    ask = ct.ask
    pcost = ct._purchase_cost(num_beneficiary)
    received = ct.destroy(num_beneficiary, beneficiary)
    xassert(received, pcost)
    assert ct.token.supply == 0
    xassert(ct._notional_supply, ct.token.supply)
    assert ct.ask < ask
Пример #4
0
def test_auction_sim():
    curve = PriceSupplyCurve(factor=0.0001, base_price=5)
    auction = Auction(factor=10**5, const=10**3)
    beneficiary = Beneficiary(issuance_fraction=0.2)
    ct = Mint(curve, beneficiary, auction)

    buys = [i * 1000 for i in range(1, 10)]
    totalcost = 0
    for num in buys:
        auction.elapsed += 3600
        # buy tokens
        ask = ct.ask
        bid = ct.bid
        cost = ct._sale_cost(num)
        totalcost += cost
        sold = ct.create(cost)
        mode = 'A' if ct.isauction else 'T'
        rt = ct.reserve_value / ct.token.supply
        s = 'bought:{} {} @ {:.2f} {:.2f}\tcost:{:.0f} mktcap:{:.0f} reserve:{:.0f} rt:{:.2f}'
        print s.format(mode, sold, bid, ask, cost, ct.mktcap, ct.reserve_value, rt)

    print 'totalcost', totalcost
    assert totalcost == ct.reserve_value
    # sell tokens
    num = sum(buys)
    print num
    pcost = ct._purchase_cost(num)
    # xassert(pcost, totalcost)
    received = ct.destroy(num)
    xassert(received, pcost)
    print "sold:", num, "for:", received, "ask:", ct.ask, ct.isauction

    # sell tokens
    rt = ct.reserve_value / ct.token.supply
    print 'reserve/token', rt
    num = ct.token.supply
    print num
    pcost = ct._purchase_cost(num)
    assert pcost == ct.reserve_value, (pcost, ct.reserve_value)
    # xassert(pcost, totalcost)
    received = ct.destroy(num, beneficiary)
    xassert(received, pcost)
    print "sold:", num, "for:", received, "ask:", ct.ask, ct.isauction
    assert ct.token.supply == 0
    assert ct.reserve_value == 0, ct.reserve_value
Пример #5
0
def test_auction_raw():
    curve = PriceSupplyCurve(factor=0.0001, base_price=5)
    auction = Auction(factor=10**5, const=10**3)
    beneficiary = Beneficiary(issuance_fraction=0)
    ct = Mint(curve, beneficiary, auction)
    assert ct._notional_supply == 0

    # buy tokens
    num = 1
    tcost = curve.cost(ct._arithmetic_supply, num)
    cost = ct._sale_cost(num)
    assert cost == tcost
    sold = ct.create(cost)
    assert sold == num and num == ct.token.supply

    # sell tokens
    pcost = ct._purchase_cost(num)
    xassert(pcost, cost)
    received = ct.destroy(num)
    xassert(received, pcost)
Пример #6
0
def gen_token():
    curve = PriceSupplyCurve(factor=0.000001, base_price=1)
    auction = Auction()
    beneficiary = Beneficiary(issuance_fraction=.2)
    ct = Mint(curve, beneficiary, auction)
    return ct