Beispiel #1
0
def calc_geyser_stakes(key, geyser, periodStartBlock, periodEndBlock):
    console.print(
        " Geyser initial snapshot for " + geyser.address,
        {
            "from": globalStartBlock,
            "to": periodEndBlock
        },
    )
    console.print(
        " Rewards for " + geyser.address,
        {
            "from": periodStartBlock,
            "to": periodEndBlock
        },
    )

    globalStartTime = web3.eth.getBlock(globalStartBlock)["timestamp"]
    periodStartTime = web3.eth.getBlock(periodStartBlock)["timestamp"]
    periodEndTime = web3.eth.getBlock(periodEndBlock)["timestamp"]

    geyserMock = BadgerGeyserMock(key)
    geyserMock.set_current_period(periodStartTime, periodEndTime)

    # Collect actions from the total history
    console.print("\n[grey]Collect Actions: Entire History[/grey]")
    actions = collect_actions_from_events(geyser, globalStartBlock,
                                          periodEndBlock)

    # Process actions from the total history
    console.print("\n[grey]Process Actions: Entire History[/grey]")
    geyserMock = process_actions(geyserMock, actions, globalStartBlock,
                                 periodEndBlock)

    return calculate_token_distributions(geyser, geyserMock, periodStartTime,
                                         periodEndTime)
Beispiel #2
0
def calculate_token_distributions(geyser, geyserMock: BadgerGeyserMock,
                                  snapshotStartTime, periodEndTime):
    """
    Tokens to Distribute:
    - get all distribution tokens
    - for each token, determine how many tokens will be distritbuted between the times specified
        - ((timeInClaimPeriod / totalTime) * initialLocked)
    """
    digg = interface.IDigg(digg_token)
    distributionTokens = geyser.getDistributionTokens()

    for token in distributionTokens:
        geyserMock.add_distribution_token(token)
        unlockSchedules = geyser.getUnlockSchedulesFor(token)
        for schedule in unlockSchedules:
            if rewards_config.debug:
                console.log(schedule)
            console.print("Adding Unlock Schedule", token, schedule)
            modified = schedule
            if token == digg_token:
                # TEST: Convert to shares
                # diggSharesValue = schedule[0]
                modified = schedule
                # diggFragmentsValue = digg.sharesToFragments(diggSharesValue)
                # modified = (diggFragmentsValue, schedule[1], schedule[2], schedule[3])
            geyserMock.add_unlock_schedule(token, modified)

    tokenDistributions = geyserMock.calc_token_distributions_in_range(
        snapshotStartTime, periodEndTime)
    userDistributions = geyserMock.calc_user_distributions(tokenDistributions)
    geyserMock.tokenDistributions = tokenDistributions
    geyserMock.userDistributions = userDistributions
    geyserMock.printState(userDistributions)
    return userDistributions
def get_distributed_in_range(key, geyser, startBlock, endBlock):
    periodEndTime = web3.eth.getBlock(endBlock)["timestamp"]
    periodStartTime = web3.eth.getBlock(startBlock)["timestamp"]

    geyserMock = BadgerGeyserMock(key)
    distributionTokens = geyser.getDistributionTokens()
    for token in distributionTokens:
        geyserMock.add_distribution_token(token)
        unlockSchedules = geyser.getUnlockSchedulesFor(token)
        for schedule in unlockSchedules:
            console.log("get_distributed_in_range", schedule)
            geyserMock.add_unlock_schedule(token, schedule)

    tokenDistributions = geyserMock.calc_token_distributions_in_range(
        periodStartTime, periodEndTime)

    return tokenDistributions
Beispiel #4
0
def calculate_token_distributions(geyser, geyserMock: BadgerGeyserMock,
                                  snapshotStartTime, periodEndTime):
    """
    Tokens to Distribute:
    - get all distribution tokens
    - for each token, determine how many tokens will be distritbuted between the times specified
        - ((timeInClaimPeriod / totalTime) * initialLocked)
    """
    distributionTokens = geyser.getDistributionTokens()
    for token in distributionTokens:
        geyserMock.add_distribution_token(token)
        unlockSchedules = geyser.getUnlockSchedulesFor(token)
        for schedule in unlockSchedules:
            console.log(schedule)
            geyserMock.add_unlock_schedule(token, schedule)

    tokenDistributions = geyserMock.calc_token_distributions_in_range(
        snapshotStartTime, periodEndTime)
    userDistributions = geyserMock.calc_user_distributions(tokenDistributions)
    geyserMock.tokenDistributions = tokenDistributions
    geyserMock.userDistributions = userDistributions
    # geyserMock.printState()
    return userDistributions
Beispiel #5
0
def process_actions(geyserMock: BadgerGeyserMock, actions, snapshotStartBlock,
                    periodEndBlock, key):
    """
    Add stakes
    Remove stakes according to unstaking rules (LIFO)
    """
    console.print(
        "[green]== Processing Claim Period Actions for {} ==[/green]\n".format(
            key))
    for user, userData in actions.items():
        table = []
        # console.print("\n= Processing actions for user: "******" =")
        latestTimestamp = 0

        # Iterate over actions, grouped by timestamp
        for timestamp, timestampEntries in userData.items():
            assert int(timestamp) > latestTimestamp
            for action in timestampEntries:
                if action.action == "Stake":
                    table.append(
                        ["stake", action["amount"], action["timestamp"]])
                    geyserMock.stake(action.user, action)
                if action.action == "Unstake":
                    table.append(
                        ["unstake", action["amount"], action["timestamp"]])
                    geyserMock.unstake(action.user, action)
            latestTimestamp = int(timestamp)

        # End accounting for user
        geyserMock.calc_end_share_seconds_for(user)

        # Print results
        # print(tabulate(table, headers=["action", "amount", "timestamp"]))
        # print("\n")
        user = geyserMock.users[user]
        table = []
        table.append([user.shareSecondsInRange, user.shareSeconds, user.total])
        # print(tabulate(table, headers=["shareSecondsInRange", "shareSeconds", "total"]))

    return geyserMock