Ejemplo n.º 1
0
def calculate_can_exchange(ctx, amount, address, verify_only, is_private):

    # don't allow exchange if sale is paused
    if Get(ctx, SALE_PAUSED_KEY):
        print("Sale is paused")
        return False

    # don't allow exchange if sale has been ended
    if Get(ctx, END_SALE_KEY):
        print("Sale has ended!")
        return False

    # Favor doing by unix time of latest block
    time_now = get_now()

    if time_now < ICO_DATE_START:
        print("Token sale has not yet begun!")
        return False

    if time_now > ICO_DATE_END:
        print("Token sale has ended! ")
        return False

    # Check overflow of public amount
    current_sold = Get(ctx, ICO_TOKEN_SOLD_KEY)

    new_total = current_sold + amount

    if new_total > TOKEN_TOTAL_PUBLIC:
        print("Amount would overflow amount for public sale")
        return False

    if amount < MIN_PUBLIC_AMOUNT:
        print("Must purchase at least 50 tokens")
        return False

    # Only need to check maximum contribution for non-private placement
    if is_private:
        return True

    if amount <= MAX_PUBLIC_AMOUNT:

        # Make sure amount is less than maximum amount
        # to reserve
        current_balance = Get(ctx, address)

        if not current_balance:
            return True

        new_total = amount + current_balance

        if new_total <= MAX_PUBLIC_AMOUNT:
            return True

    print("Transaction exceeds maximum contribution")
    return False
Ejemplo n.º 2
0
def do_transfer(ctx, t_from, t_to, amount):

    if amount <= 0:
        print("Invalid amount")
        return False

    if len(t_to) != 20:
        print("Invalid address")
        return False

    if len(t_from) != 20:
        print("Invalid address")
        return False

    if CheckWitness(t_from):

        if t_from == t_to:
            print("transfer to self!")
            return True

        from_val = Get(ctx, t_from)

        if from_val < amount:
            print("insufficient funds")
            return False

        if is_private_placement(ctx, t_from):
            time_now = get_now()
            if time_now < PP_LOCKUP_END:
                print("Token still in 1 year private placement lockup!")
                return False

        if from_val == amount:
            Delete(ctx, t_from)

        else:
            difference = from_val - amount
            Put(ctx, t_from, difference)

        to_value = Get(ctx, t_to)

        to_total = to_value + amount

        Put(ctx, t_to, to_total)

        OnTransfer(t_from, t_to, amount)

        return True
    else:
        print("from address is not the tx sender")

    return False
Ejemplo n.º 3
0
def mint_team(ctx):

    if not CheckWitness(TOKEN_OWNER):
        print("You are not asset owner!")
        return False

    # Can allow mint_team if after ICO_DATE_END or if END_SALE_KEY
    # has been set.
    ended_by_owner = Get(ctx, END_SALE_KEY)

    time_now = get_now()
    if time_now < ICO_DATE_END and not ended_by_owner:
        print("Sale not yet over, need to wait to mintTeam tokens")
        return False

    if Get(ctx, TEAM_ADDRESS):
        print("Already distributed team portion!")
        return False


    # Get ratio of tokens sold from 66 million (for instance 50 mil / 66 mil = 0.7575)
    sold = Get(ctx, ICO_TOKEN_SOLD_KEY)

    # Mint that ratio of team tokens to maintain 2:1 ratio
    # For example, if 50 mil public tokens sold, have 25 mil for team
    # Need to multiply before divide because there is no floating point support
    amount_team = (sold * TOKEN_TEAM) / TOKEN_TOTAL_PUBLIC

    current_in_circulation = Get(ctx, TOKEN_IN_CIRCULATION_KEY)

    new_total = current_in_circulation + amount_team

    if new_total > TOKEN_TOTAL_SUPPLY:
        print("Amount greater than tokens available")
        return False

    # TODO
    # Put team tokens in owner address, but maybe want to change
    # this to another wallet address
    Put(ctx, TEAM_ADDRESS, amount_team)

    return add_to_circulation(ctx, amount_team)