def main():
    block = 12428803
    badger = connect_badger()

    bbadger = list(
        calculate_sett_balances(badger, "native.badger",
                                block).userBalances.keys())

    uniBadger = list(
        calculate_sett_balances(badger, "native.uniBadgerWbtc",
                                block).userBalances.keys())

    sushiBadger = list(
        calculate_sett_balances(badger, "native.sushiBadgerWbtc",
                                block).userBalances.keys())

    badger_holders, digg_holders = fetch_wallet_balances(
        1, 1, badger.digg, block)

    with open("badger_holders.json", "w") as fp:
        json.dump(
            list(
                set([
                    *bbadger, *uniBadger, *sushiBadger,
                    *list(badger_holders.keys())
                ])),
            fp,
        )
Пример #2
0
def calc_meta_farm_rewards(badger, name, harvestBlock):
    console.log("Calculating rewards for {} harvest at {}".format(
        name, harvestBlock))
    harvestBlock = int(harvestBlock)
    sett = badger.getSett(name)
    balances = calculate_sett_balances(badger, name, harvestBlock)
    return balances
Пример #3
0
def main():
    badger = connect_badger("deploy-final.json")
    setts = [
        "native.renCrv",
        "native.sbtcCrv",
        "native.renCrv",
        "harvest.renCrv",
        "yearn.wbtc",
        "native.sushiWbtcEth",
    ]
    block = 12382594
    old_scores = json.load(open("scores.json"))
    for addr, scoreInfo in old_scores.items():
        for cond, amount in scoreInfo.items():
            if cond == "cond5":
                scoreInfo[cond] = 2

    vaultDepositers = []
    for s in setts:
        balances = calculate_sett_balances(badger, s, block)
        for user in balances:
            if user.balance > 0:
                vaultDepositers.append(web3.toChecksumAddress(user.address))

    for addr in vaultDepositers:
        if addr not in old_scores.keys():
            old_scores[addr] = {"cond8": 2}
        else:
            old_scores[addr]["cond8"] = 2
    threeList = []
    fourList = []
    for addr, info in old_scores.items():
        totalScore = sum(info.values())
        if totalScore >= 3:
            threeList.append(addr)
        if totalScore >= 4:
            fourList.append(addr)

    print(len(threeList))
    print(len(fourList))

    with open("scores,json", "w") as fp:
        json.dump(old_scores, fp)

    with open("final_list.json", "w") as fp2:
        json.dump(fourList, fp2)
Пример #4
0
def calc_snapshot(
    badger, name, startBlock, endBlock, nextCycle, boosts, unclaimedBalances
):
    digg = interface.IDigg(DIGG)

    console.log("==== Processing rewards for {} at {} ====".format(name, endBlock))

    rewards = RewardsList(nextCycle, badger.badgerTree)

    sett = badger.getSett(name)
    startTime = web3.eth.getBlock(startBlock)["timestamp"]

    endTime = web3.eth.getBlock(endBlock)["timestamp"]

    userBalances = calculate_sett_balances(badger, name, endBlock)

    apyBoosts = {}
    if name in NON_NATIVE_SETTS:
        console.log(
            "{} users out of {} boosted in {}".format(
                len(userBalances), len(boosts), name
            )
        )
        preBoost = {}
        for user in userBalances:
            preBoost[user.address] = userBalances.percentage_of_total(user.address)

        for user in userBalances:
            boostAmount = boosts.get(user.address, 1)
            user.boost_balance(boostAmount)

        for user in userBalances:
            postBoost = userBalances.percentage_of_total(user.address)
            apyBoosts[user.address] = postBoost / preBoost[user.address]

    schedulesByToken = parse_schedules(
        badger.rewardsLogger.getAllUnlockSchedulesFor(sett)
    )

    for token, schedules in schedulesByToken.items():
        endDist = get_distributed_for_token_at(token, endTime, schedules, name)
        startDist = get_distributed_for_token_at(token, startTime, schedules, name)
        tokenDistribution = int(endDist) - int(startDist)
        # Distribute to users with rewards list
        # Make sure there are tokens to distribute (some geysers only
        # distribute one token)
        if token == DIGG:

            # if name in NATIVE_DIGG_SETTS:
            #    tokenDistribution = tokenDistribution * diggAllocation
            # else:
            #    tokenDistribution = tokenDistribution * (1 - diggAllocation)
            fragments = digg.sharesToFragments(tokenDistribution) / 1e9
            console.log(
                "{} DIGG tokens distributed".format(
                    digg.sharesToFragments(tokenDistribution) / 1e9
                )
            )
            rewardsLog.add_total_token_dist(name, token, fragments)
        elif token == "0x20c36f062a31865bED8a5B1e512D9a1A20AA333A":
            console.log("{} DFD tokens distributed".format(tokenDistribution / 1e18))
            rewardsLog.add_total_token_dist(name, token, tokenDistribution / 1e18)
        else:
            badgerAmount = tokenDistribution / 1e18
            console.log("{} Badger token distributed".format(badgerAmount))
            rewardsLog.add_total_token_dist(name, token, tokenDistribution / 1e18)

        if tokenDistribution > 0:
            sumBalances = sum([b.balance for b in userBalances])
            rewardsUnit = tokenDistribution / sumBalances
            totalRewards = 0
            console.log("Processing rewards for {} addresses".format(len(userBalances)))
            for user in userBalances:
                addr = web3.toChecksumAddress(user.address)

                token = web3.toChecksumAddress(token)
                rewardAmount = user.balance * rewardsUnit
                totalRewards += rewardAmount
                ## If giving rewards to tree , distribute them to users with unlcaimed bals
                if addr == BADGER_TREE:
                    if name == "native.cvx":
                        console.log(
                            "Distributing {} rewards to {} unclaimed bCvx holders".format(
                                rewardAmount / 1e18, len(unclaimedBalances["bCvx"])
                            )
                        )
                        totalbCvxBal = sum(unclaimedBalances["bCvx"].values())
                        cvxRewardsUnit = rewardAmount / totalbCvxBal
                        for addr, bal in unclaimedBalances["bCvx"].items():
                            rewards.increase_user_rewards(
                                web3.toChecksumAddress(addr),
                                token,
                                int(cvxRewardsUnit * bal),
                            )
                    if name == "native.cvxCrv":

                        console.log(
                            "Distributing {} rewards to {} unclaimed bCvxCrv holders".format(
                                rewardAmount / 1e18, len(unclaimedBalances["bCvxCrv"])
                            )
                        )

                        totalbCvxCrvBal = sum(unclaimedBalances["bCvxCrv"].values())
                        bCvxCrvRewardsUnit = rewardAmount / totalbCvxCrvBal
                        for addr, bal in unclaimedBalances["bCvxCrv"].items():
                            rewards.increase_user_rewards(
                                web3.toChecksumAddress(addr),
                                token,
                                int(bCvxCrvRewardsUnit * bal),
                            )
                else:
                    rewards.increase_user_rewards(addr, token, int(rewardAmount))

            console.log(
                "Token Distribution: {}\nRewards Released: {}".format(
                    tokenDistribution / 1e18, totalRewards / 1e18
                )
            )
            console.log("Diff {}\n\n".format((abs(tokenDistribution - totalRewards))))

    return rewards, apyBoosts
Пример #5
0
def main():
    badger = connect_badger(badger_config.prod_json,
                            load_keeper=False,
                            load_deployer=False)
    bBadger = badger.getSett("native.badger")
    wbtcBadgerUni = badger.getSett("native.uniBadgerWbtc")
    wbtcBadgerSlp = badger.getSett("native.sushiBadgerWbtc")
    crvRenwbtc = badger.getSett("native.renCrv")
    crvRenWsBtc = badger.getSett("native.sbtcCrv")
    tbtc_sbtcCrv = badger.getSett("native.tbtcCrv")
    crvRenWbtc_harvest = badger.getSett("harvest.renCrv")
    wbtcWethSLP = badger.getSett("native.sushiWbtcEth")

    wbtcDiggUni = badger.getSett("native.uniDiggWbtc")
    wbtcDiggSlp = badger.getSett("native.sushiDiggWbtc")
    bDigg = badger.getSett("native.digg")

    condition1Blocks = [11425076, 11548798, 11613974, 11679140]
    condition2Blocks = [11731159, 11835137, 11945691, 12056056]
    condition3Blocks = [11425076, 11613974, 11835137, 12056056]
    condition4Blocks = [11731159, 11835137, 11945691, 12056056]
    condition5Blocks = [11880719, 12056056]

    condition1Addresses = []
    for block in condition1Blocks:
        bBadgerAddreses = filter_zero(
            calculate_sett_balances(badger, "native.badger", bBadger,
                                    block)).keys()
        wbtcBadgerUniAddresses = filter_zero(
            calculate_sett_balances(badger, "native.uniBadgerWbtc",
                                    wbtcBadgerUni, block)).keys()
        wbtcBadgerSlpAddreses = filter_zero(
            calculate_sett_balances(badger, "native.sushiBadgerWbtc",
                                    wbtcBadgerSlp, block)).keys()
        combinedAddrs = set([
            *bBadgerAddreses, *wbtcBadgerUniAddresses, *wbtcBadgerSlpAddreses
        ])
        condition1Addresses.append(combinedAddrs)

    add_addresses(set.intersection(*condition1Addresses), 1)

    condition2Addresses = []
    for block in condition2Blocks:
        bBadgerAddreses = filter_zero(
            calculate_sett_balances(badger, "native.badger", bBadger,
                                    block)).keys()
        wbtcBadgerUniAddresses = filter_zero(
            calculate_sett_balances(badger, "native.uniBadgerWbtc",
                                    wbtcBadgerUni, block)).keys()
        wbtcBadgerSlpAddreses = filter_zero(
            calculate_sett_balances(badger, "native.sushiBadgerWbtc",
                                    wbtcBadgerSlp, block)).keys()
        combinedAddrs = set([
            *bBadgerAddreses, *wbtcBadgerUniAddresses, *wbtcBadgerSlpAddreses
        ])
        condition2Addresses.append(combinedAddrs)

    add_addresses(set.intersection(*condition2Addresses), 1)

    condition3Addresses = []
    for block in condition3Blocks:
        crvRenwbtcAddresses = filter_zero(
            calculate_sett_balances(badger, "native.renCrv", crvRenwbtc,
                                    block)).keys()
        crvRenWsBtcAddresses = filter_zero(
            calculate_sett_balances(badger, "native.sbtcCrv", crvRenWsBtc,
                                    block)).keys()
        tbtc_sbtcAddresses = filter_zero(
            calculate_sett_balances(badger, "native.tbtcCrv", tbtc_sbtcCrv,
                                    block)).keys()
        harvestRenBtcAddresses = filter_zero(
            calculate_sett_balances(badger, "harvest.renCrv",
                                    crvRenWbtc_harvest, block)).keys()
        wbtcWethSLPAddresses = filter_zero(
            calculate_sett_balances(badger, "native.sushiWbtcEth", wbtcWethSLP,
                                    block)).keys()
        combinedAddrs = set([
            *crvRenwbtcAddresses,
            *crvRenWsBtcAddresses,
            *tbtc_sbtcAddresses,
            *harvestRenBtcAddresses,
            *wbtcWethSLPAddresses,
        ])
        condition3Addresses.append(combinedAddrs)

    add_addresses(set.intersection(*condition3Addresses), 1)

    condition4Addresses = []
    for block in condition4Blocks:
        uniDiggAddrs = filter_zero(
            calculate_sett_balances(badger, "native.uniDiggWbtc", wbtcDiggUni,
                                    block)).keys()
        sushiDiggAddrs = filter_zero(
            calculate_sett_balances(badger, "native.sushiDiggWbtc",
                                    wbtcDiggSlp, block)).keys()
        bDiggAddrs = filter_zero(
            calculate_sett_balances(badger, "native.digg", bDigg,
                                    block)).keys()
        combinedAddrs = set([*uniDiggAddrs, *sushiDiggAddrs, *bDiggAddrs])
        condition4Addresses.append(combinedAddrs)

    add_addresses(set.intersection(*condition4Addresses), 1)

    addrs = []
    uniDiggBalances_old = filter_zero(
        calculate_sett_balances(badger, "native.uniDiggWbtc", wbtcDiggUni,
                                condition5Blocks[0]))
    uniDiggBalances_new = filter_zero(
        calculate_sett_balances(badger, "native.uniDiggWbtc", wbtcDiggUni,
                                condition5Blocks[1]))
    for addr, bal in uniDiggBalances_new.items():
        old_bal = uniDiggBalances_old.get(addr, 0)
        if bal > old_bal:
            addrs.append(addr)

    sushiDiggBalances_old = filter_zero(
        calculate_sett_balances(badger, "native.sushiDiggWbtc", wbtcDiggSlp,
                                condition5Blocks[0]))
    sushiDiggBalances_new = filter_zero(
        calculate_sett_balances(badger, "native.sushiDiggWbtc", wbtcDiggSlp,
                                condition5Blocks[1]))
    for addr, bal in sushiDiggBalances_new.items():
        old_bal = sushiDiggBalances_old.get(addr, 0)
        if bal > old_bal:
            addrs.append(addr)

    bDiggBalances_old = filter_zero(
        calculate_sett_balances(badger, "native.digg", bDigg,
                                condition5Blocks[0]))
    bDiggBalances_new = filter_zero(
        calculate_sett_balances(badger, "native.digg", bDigg,
                                condition5Blocks[1]))
    for addr, bal in bDiggBalances_new.items():
        old_bal = bDiggBalances_old.get(addr, 0)
        if bal > old_bal:
            addrs.append(addr)

    add_addresses(set(addrs), 6)
    with open("yearn-whitelist.json", "w") as fp:
        json.dump(early_access, fp, indent=2)
Пример #6
0
def badger_boost(badger, currentBlock):
    console.log("Calculating boost ...")
    allSetts = badger.sett_system.vaults
    diggSetts = UserBalances()
    badgerSetts = UserBalances()
    nonNativeSetts = UserBalances()
    boostInfo = {}
    for name, sett in allSetts.items():
        if name in ["experimental.digg"]:
            continue
        balances = calculate_sett_balances(badger, name, currentBlock)
        balances = convert_balances_to_usd(sett, name, balances)
        if name in [
                "native.uniDiggWbtc", "native.sushiDiggWbtc", "native.digg"
        ]:
            diggSetts = combine_balances([diggSetts, balances])
        elif name in [
                "native.badger",
                "native.uniBadgerWbtc",
                "native.sushiBadgerWbtc",
        ]:
            badgerSetts = combine_balances([badgerSetts, balances])
        else:
            nonNativeSetts = combine_balances([nonNativeSetts, balances])

    sharesPerFragment = badger.digg.logic.UFragments._sharesPerFragment()
    badger_wallet_balances, digg_wallet_balances, _ = fetch_wallet_balances(
        sharesPerFragment, currentBlock)

    console.log("{} Badger balances fetched, {} Digg balances fetched".format(
        len(badger_wallet_balances), len(digg_wallet_balances)))
    badger_wallet_balances = UserBalances([
        UserBalance(addr, bal * prices[BADGER], BADGER)
        for addr, bal in badger_wallet_balances.items()
    ])

    digg_wallet_balances = UserBalances([
        UserBalance(addr, bal * prices[DIGG], DIGG)
        for addr, bal in digg_wallet_balances.items()
    ])
    badgerSetts = filter_dust(
        combine_balances([badgerSetts, badger_wallet_balances]))
    diggSetts = filter_dust(combine_balances([diggSetts,
                                              digg_wallet_balances]))
    allAddresses = calc_union_addresses(diggSetts, badgerSetts, nonNativeSetts)

    console.log("Non native Setts before filter {}".format(
        len(nonNativeSetts)))
    nonNativeSetts = filter_dust(nonNativeSetts)
    console.log("Non native Setts after filter {}".format(len(nonNativeSetts)))

    console.log("Filtered balances < $1")

    console.log("{} addresses collected for boost calculation".format(
        len(allAddresses)))
    stakeRatiosList = [
        calc_stake_ratio(addr, diggSetts, badgerSetts, nonNativeSetts)
        for addr in allAddresses
    ]
    stakeRatios = dict(zip(allAddresses, stakeRatiosList))
    stakeRatios = OrderedDict(
        sorted(stakeRatios.items(), key=lambda t: t[1], reverse=True))

    for addr in allAddresses:
        boostInfo[addr.lower()] = {
            "nativeBalance": 0,
            "nonNativeBalance": 0,
            "stakeRatio": 0,
        }

    for user in badgerSetts:
        boostInfo[user.address.lower()]["nativeBalance"] += user.balance

    for user in diggSetts:
        boostInfo[user.address.lower()]["nativeBalance"] += user.balance

    for user in nonNativeSetts:
        boostInfo[user.address.lower()]["nonNativeBalance"] += user.balance

    for addr, ratio in stakeRatios.items():
        boostInfo[addr.lower()]["stakeRatio"] = ratio

    sortedNonNative = UserBalances(
        sorted(
            nonNativeSetts.userBalances.values(),
            key=lambda u: stakeRatios[u.address],
            reverse=True,
        ))
    nonNativeTotal = sortedNonNative.total_balance()
    percentageNonNative = {}
    for user in sortedNonNative:
        percentage = user.balance / nonNativeTotal
        percentageNonNative[user.address] = percentage

    cumulativePercentages = dict(
        zip(percentageNonNative.keys(),
            calc_cumulative(percentageNonNative.values())))
    badgerBoost = dict(
        zip(cumulativePercentages.keys(),
            calc_boost(cumulativePercentages.values())))
    for addr, boost in badgerBoost.items():
        # Users with no stake ratio have a boost of 1
        if stakeRatios[addr] == 0:
            badgerBoost[addr] = 1

    console.log(len(badgerBoost))

    return badgerBoost, boostInfo
Пример #7
0
def calc_tree_rewards(badger, startBlock, endBlock, nextCycle):

    # sharesPerFragment = badger.digg.logic.UFragments._sharesPerFragment()
    # _, _2, ibbtc_balances = fetch_wallet_balances(sharesPerFragment, endBlock)

    treeDists = fetch_tree_distributions(startBlock, endBlock)
    console.log(
        "Calculating rewards for {} harvests between {} and {}".format(
            len(treeDists), startBlock, endBlock
        )
    )
    rewards = RewardsList(nextCycle, badger.badgerTree)
    rewardsData = {}
    for dist in treeDists:
        blockNumber = dist["blockNumber"]
        strategy = dist["id"].split("-")[0]
        token = dist["token"]["address"]
        symbol = dist["token"]["symbol"]
        amountToDistribute = int(dist["amount"])

        console.log("Processing harvest...")
        console.log("Token:{}".format(symbol))
        console.log("Amount:{} \n".format(amountToDistribute / 1e18))

        if symbol not in rewardsData:
            rewardsData[symbol] = 0

        rewardsData[symbol] += amountToDistribute / 1e18
        settName = badger.getSettFromStrategy(strategy)
        balances = calculate_sett_balances(badger, settName, int(blockNumber))
        totalBalance = sum([u.balance for u in balances])
        rewardsUnit = amountToDistribute / totalBalance
        rewardsLog.add_total_token_dist(
            settName, web3.toChecksumAddress(token), amountToDistribute / 1e18
        )
        # totalIbbtcBalance = sum(ibbtc_balances.values())
        for user in balances:
            userReward = rewardsUnit * user.balance
            # if user.address in [a.lower() for a in PEAK_ADDRESSES]:
            #     ibbtcRewardsUnit = userReward / totalIbbtcBalance

            #     console.log(
            #         "Distributing {} {} to {} ibbtc holders from {}".format(
            #             userReward / 1e18, symbol, len(ibbtc_balances), settName
            #         )
            #     )

            #     # Redistribute peak addresses rewards to ibbtc users
            #     for addr, balance in ibbtc_balances.items():

            #         rewards.increase_user_rewards(
            #             web3.toChecksumAddress(addr),
            #             token,
            #             int(ibbtcRewardsUnit * balance),
            #         )
            # else:
            rewards.increase_user_rewards(
                web3.toChecksumAddress(user.address),
                web3.toChecksumAddress(token),
                int(userReward),
            )

    console.log(rewardsData)

    return rewards