Exemplo n.º 1
0
def main():
    badger = connect_badger(badger_config.prod_json,
                            load_keeper=True,
                            load_guardian=True)
    pendingContentHash = (
        "0x346ec98585b52d981d43584477e1b831ce32165cb8e0a06d14d236241b36328e")
    pendingFile = "rewards-1-" + str(pendingContentHash) + ".json"
    with open(pendingFile) as f:
        after_file = json.load(f)

    pendingRewards = after_file
    # pendingRewards = fetch_current_rewards_tree(badger)
    currentRewards = fetch_current_rewards_tree(badger)

    accounts[0].transfer(badger.keeper, Wei("5 ether"))
    accounts[0].transfer(badger.guardian, Wei("5 ether"))

    # Upgrade Rewards Tree
    multi = GnosisSafe(badger.devMultisig)

    newLogic = BadgerTree.at("0x0f81D3f48Fedb8E67a5b87A8a4De57766157f19B")

    multi.execute(
        MultisigTxMetadata(description="Upgrade Tree", ),
        {
            "to":
            badger.opsProxyAdmin.address,
            "data":
            badger.opsProxyAdmin.upgrade.encode_input(badger.badgerTree,
                                                      newLogic),
        },
    )

    assert (badger.badgerTree.hasRole(DEFAULT_ADMIN_ROLE,
                                      badger.devMultisig.address) == True)
    assert badger.badgerTree.getRoleMemberCount(DEFAULT_ADMIN_ROLE) == 1

    assert badger.badgerTree.hasRole(ROOT_PROPOSER_ROLE,
                                     badger.keeper.address) == True
    assert badger.badgerTree.getRoleMemberCount(ROOT_PROPOSER_ROLE) == 1

    # assert badger.badgerTree.hasRole(ROOT_VALIDATOR_ROLE, badger.guardian.address) == True
    # assert badger.badgerTree.getRoleMemberCount(ROOT_VALIDATOR_ROLE) == 1

    assert badger.badgerTree.hasRole(PAUSER_ROLE,
                                     badger.guardian.address) == True
    assert badger.badgerTree.getRoleMemberCount(PAUSER_ROLE) == 1

    assert badger.badgerTree.hasRole(UNPAUSER_ROLE,
                                     badger.devMultisig.address) == True
    assert badger.badgerTree.getRoleMemberCount(UNPAUSER_ROLE) == 1

    verify_rewards(
        badger,
        pendingRewards["startBlock"],
        pendingRewards["endBlock"],
        currentRewards,
        pendingRewards,
    )
Exemplo n.º 2
0
def generate_rewards_in_range(badger, startBlock, endBlock, pastRewards):
    blockDuration = endBlock - startBlock

    nextCycle = getNextCycle(badger)

    currentMerkleData = fetchCurrentMerkleData(badger)
    #sushiRewards = calc_sushi_rewards(badger,startBlock,endBlock,nextCycle,retroactive=False)
    #farmRewards = fetch_current_harvest_rewards(badger,startBlock, endBlock,nextCycle)

    geyserRewards = calc_geyser_rewards(badger, startBlock, endBlock, nextCycle)
    rewardsLogger.save("rewards")

    #newRewards = combine_rewards([geyserRewards,farmRewards,sushiRewards],nextCycle,badger.badgerTree)
    cumulativeRewards = process_cumulative_rewards(pastRewards, geyserRewards)

    # Take metadata from geyserRewards
    console.print("Processing to merkle tree")
    merkleTree = rewards_to_merkle_tree(
        cumulativeRewards, startBlock, endBlock, {}
    )

    # Publish data
    rootHash = hash(merkleTree["merkleRoot"])
    contentFileName = content_hash_to_filename(rootHash)

    console.log(
        {
            "merkleRoot": merkleTree["merkleRoot"],
            "rootHash": str(rootHash),
            "contentFile": contentFileName,
            "startBlock": startBlock,
            "endBlock": endBlock,
            "currentContentHash": currentMerkleData["contentHash"],
        }
    )

    print("Uploading to file " + contentFileName)
    # TODO: Upload file to AWS & serve from server
    with open(contentFileName, "w") as outfile:
        json.dump(merkleTree, outfile,indent=4)

    with open(contentFileName) as f:
        after_file = json.load(f)

    # Sanity check new rewards file
    
    verify_rewards(
        badger,
        startBlock,
        endBlock,
        pastRewards,
        after_file,
    )

    return {
        "contentFileName": contentFileName,
        "merkleTree": merkleTree,
        "rootHash": rootHash,
    }
Exemplo n.º 3
0
def approve_root(badger: BadgerSystem):
    badgerTree = badger.badgerTree
    if not badgerTree.hasPendingRoot():
        console.print("No pending root")
        return False

    if rpc.is_active():
        badger.guardian = accounts.at(
            "0x626F69162Ea1556A75Dd4443D87D2fe38dd25901", force=True)

    current = fetchCurrentMerkleData(badger)
    pending = fetchPendingMerkleData(badger)

    (publishedRewards, sb, eb) = get_last_published_cycle(badger)
    (proposedRewards, startBlock, endBlock) = get_last_proposed_cycle(badger)

    console.print(proposedRewards["merkleRoot"])

    rootHash = hash(proposedRewards["merkleRoot"])
    contentFileName = content_hash_to_filename(rootHash)
    print("Uploading to file " + contentFileName)

    with open(contentFileName, "w") as outfile:
        json.dump(proposedRewards, outfile, indent=4)

    with open(contentFileName) as f:
        after_file = json.load(f)

    console.print(contentFileName)

    print(
        proposedRewards["merkleRoot"],
        startBlock,
        endBlock,
        badgerTree.lastProposeStartBlock(),
        badgerTree.lastProposeEndBlock(),
    )

    verify_rewards(badger, startBlock, endBlock, publishedRewards,
                   proposedRewards)

    badgerTree.approveRoot(
        proposedRewards["merkleRoot"],
        pending["contentHash"],
        proposedRewards["cycle"],
        startBlock,
        endBlock,
        {
            "from": badger.guardian,
            "gas_limit": 3000000,
            "allow_revert": True
        },
    )

    upload(contentFileName)
def generate_rewards_in_range(badger, startBlock, endBlock, pastRewards,
                              saveLocalFile):
    endBlock = endBlock
    blockDuration = endBlock - startBlock

    nextCycle = getNextCycle(badger)

    currentMerkleData = fetchCurrentMerkleData(badger)
    # farmRewards = fetch_current_harvest_rewards(badger,startBlock, endBlock,nextCycle)
    unclaimedAddresses = []
    for addr, data in pastRewards["claims"].items():
        tokens = data["tokens"]
        if BCVX in tokens or BCVXCRV in tokens:
            unclaimedAddresses.append(addr)

    sushiRewards = calc_all_sushi_rewards(badger, startBlock, endBlock,
                                          nextCycle)
    treeRewards = calc_tree_rewards(badger, startBlock, endBlock, nextCycle)
    settRewards = calc_sett_rewards(
        badger,
        startBlock,
        endBlock,
        nextCycle,
        get_unclaimed_rewards(unclaimedAddresses),
    )

    newRewards = combine_rewards([settRewards, treeRewards, sushiRewards],
                                 nextCycle, badger.badgerTree)
    cumulativeRewards = process_cumulative_rewards(pastRewards, newRewards)

    # Take metadata from geyserRewards
    console.print("Processing to merkle tree")
    merkleTree = rewards_to_merkle_tree(cumulativeRewards, startBlock,
                                        endBlock, {})

    # Publish data
    rootHash = keccak(merkleTree["merkleRoot"])

    contentFileName = content_hash_to_filename(rootHash)

    console.log({
        "merkleRoot": merkleTree["merkleRoot"],
        "rootHash": str(rootHash),
        "contentFile": contentFileName,
        "startBlock": startBlock,
        "endBlock": endBlock,
        "currentContentHash": currentMerkleData["contentHash"],
    })
    rewardsLog.set_merkle_root(merkleTree["merkleRoot"])
    rewardsLog.set_content_hash(str(rootHash))
    rewardsLog.set_start_block(startBlock)
    rewardsLog.set_end_block(endBlock)
    print("Uploading to file " + contentFileName)

    rewardsLog.save(nextCycle)
    # TODO: Upload file to AWS & serve from server
    if saveLocalFile:
        with open(contentFileName, "w") as outfile:
            json.dump(merkleTree, outfile, indent=4)

    # Sanity check new rewards file

    verify_rewards(badger, startBlock, endBlock, pastRewards, merkleTree)

    return {
        "contentFileName": contentFileName,
        "merkleTree": merkleTree,
        "rootHash": rootHash,
    }