def main(): badger = connect_badger(badger_config.prod_json, load_keeper=True, load_guardian=True) pendingContentHash = "0x07baafa95bf7c39ba948753dda64b2e82854b5a7597f6de9e15c23a96d0bfad3" 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.deploy({"from": badger.keeper}) multi.execute( MultisigTxMetadata( description="Upgrade Tree", ), { "to": badger.devProxyAdmin.address, "data": badger.devProxyAdmin.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) # push_rewards(badger, pendingContentHash) if rpc.is_active(): test_claims(badger, pendingRewards["startBlock"], pendingRewards["endBlock"], currentRewards, pendingRewards)
def main(): test = False badger = connect_badger(load_root_proposer=True) nextCycle = badger.badgerTree.currentCycle() + 1 startBlock = 0 endBlock = chain.height currentRewards = fetch_current_rewards_tree(badger) console.log(currentRewards["startBlock"]) console.log(currentRewards["endBlock"]) rewards = calc_tree_rewards(badger, startBlock, endBlock, nextCycle) cumulative_rewards = process_cumulative_rewards(currentRewards, rewards) merkleTree = rewards_to_merkle_tree(cumulative_rewards, startBlock, endBlock, {}) rootHash = web3.toHex(web3.keccak(text=merkleTree["merkleRoot"])) contentFileName = "rewards-" + str(chain.id) + "-" + str(rootHash) + ".json" console.log("Saving merkle tree as {}".format(contentFileName)) with open(contentFileName, "w") as f: json.dump(merkleTree, f, indent=4) if not test: badger.badgerTree.proposeRoot( merkleTree["merkleRoot"], rootHash, nextCycle, currentRewards["startBlock"], currentRewards["endBlock"], {"from": badger.root_proposer, "gas_price": gas_strategy}, ) upload(contentFileName, merkleTree, publish=False)
def main(): badger = connect_badger(badger_config.prod_json) # Get latest block rewards were updated currentMerkleData = badger.badgerTree.getCurrentMerkleData() console.log("currentMerkleData", currentMerkleData) print("Run at", int(time.time())) currentRewards = fetch_current_rewards_tree(badger) lastClaimEnd = int(currentRewards["endBlock"]) startBlock = lastClaimEnd + 1 # Claim at current block claimAt = chain.height print("Claim Section", startBlock, claimAt) # If sufficient time has passed since last root proposal, propose a new root rootProposed = run_action(badger, { "action": "rootUpdater", "startBlock": startBlock, "endBlock": claimAt }) # If there is a pending root, approve after independently verifying it rootApproved = run_action(badger, { "action": "guardian", "startBlock": startBlock, "endBlock": claimAt })
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, )
def get_last_published_cycle(badger): # Fetch the appropriate file currentRewards = fetch_current_rewards_tree(badger) lastClaimEnd = int(currentRewards["endBlock"]) lastClaimStart = int(currentRewards["startBlock"]) # Sanity check: Ensure previous cycle was not too long assert lastClaimStart > lastClaimEnd - rewards_config.maxStartBlockAge # Sanity check: Ensure previous end block is not too far in the past assert lastClaimEnd > chain.height - rewards_config.maxStartBlockAge # Sanity check: Ensure start block is not too close to end block return (currentRewards, lastClaimStart, lastClaimEnd)
def calc_next_cycle_range(badger): print("Run at", int(time.time())) # Fetch the appropriate file currentRewards = fetch_current_rewards_tree(badger) lastClaimEnd = badger.badgerTree.lastPublishEndBlock() startBlock = lastClaimEnd + 1 # Claim at current block endBlock = chain.height #Sanity check: Ensure start block is not too far in the past #assert startBlock > endBlock - rewards_config.maxStartBlockAge # Sanity check: Ensure start block is not too close to end block return (currentRewards, startBlock, endBlock)
def main(): test = True badger = connect_badger(badger_config.prod_json, load_deployer=False) nextCycle = badger.badgerTree.currentCycle() + 1 startBlock = 11951320 endBlock = chain.height rewards = calc_sushi_rewards(badger, startBlock, endBlock, nextCycle, retroactive=True) rewardsLogger.save("retroactive-xsushi") currentRewards = fetch_current_rewards_tree(badger) cumulative_rewards = process_cumulative_rewards(currentRewards, rewards) merkleTree = rewards_to_merkle_tree(cumulative_rewards, startBlock, endBlock, {}) rootHash = web3.toHex(web3.keccak(text=merkleTree["merkleRoot"])) contentFileName = ("rewards-" + str(chain.id) + "-" + str(merkleTree["merkleRoot"]) + ".json") console.log("Saving merkle tree as {}".format(contentFileName)) with open(contentFileName, "w") as f: json.dump(merkleTree, f, indent=4) if not test: badger.badgerTree.proposeRoot( merkleTree["merkleRoot"], rootHash, nextCycle, { "from": badger.keeper, "gas_price": gas_strategy }, ) badger.badgerTree.approveRoot( merkleTree["merkleRoot"], rootHash, nextCycle, { "from": badger.keeper, "gas_price": gas_strategy }, )
def fetch_rewards_preconditions(badger): print("Run at", int(time.time())) # Fetch the appropriate file currentRewards = fetch_current_rewards_tree(badger) lastClaimEnd = int(currentRewards["endBlock"]) startBlock = lastClaimEnd + 1 # Claim at current block endBlock = chain.height # Sanity check: Ensure start block is not too far in the past assert startBlock > endBlock - rewards_config.maxStartBlockAge # Sanity check: Ensure start block is not too close to end block print("Claim Section", startBlock, endBlock) return (startBlock, endBlock)
def test_rewards_flow(): badger = connect_badger(badger_config.prod_json) tree = badger.badgerTree pct_claims_to_verify = 0.001 tokens_to_check = [ badger.token, badger.digg.token, interface.IERC20(registry.sushi.xsushiToken), interface.IERC20(registry.harvest.farmToken), ] # newLogic = BadgerTree.deploy({"from": badger.deployer}) newLogic = BadgerTree.at("0x0f81D3f48Fedb8E67a5b87A8a4De57766157f19B") multi = GnosisSafe(badger.opsMultisig) # Test claimable amounts # ===== Test VS Existing List ===== active_claims = fetch_current_rewards_tree(badger) claims = active_claims["claims"] users_to_verify = [] # Test claims with latest root for user, claim in claims.items(): roll = random.random() if roll < pct_claims_to_verify: console.print(roll, pct_claims_to_verify) users_to_verify.append(user) test_claim(badger, user, claim, tokens_to_check) retroactive_content_hash = "0x346ec98585b52d981d43584477e1b831ce32165cb8e0a06d14d236241b36328e" retroactive_file_name = "rewards-1-" + retroactive_content_hash + ".json" with open(retroactive_file_name) as f: rewards = json.load(f) # Update to new root with xSushi and FARM rootProposer = accounts.at(tree.getRoleMember(ROOT_PROPOSER_ROLE, 0), force=True) rootValidator = accounts.at(tree.getRoleMember(ROOT_VALIDATOR_ROLE, 0), force=True) lastProposeEndBlock = tree.lastProposeEndBlock() currentCycle = tree.currentCycle() endBlock = chain.height root = rewards["merkleRoot"] # root = tree.merkleRoot() tree.proposeRoot(root, retroactive_content_hash, currentCycle + 1, lastProposeEndBlock + 1, endBlock, {"from": rootProposer}) tree.approveRoot(root, retroactive_content_hash, currentCycle + 1, lastProposeEndBlock + 1, endBlock, {"from": rootValidator}) assert tree.merkleRoot() == root assert tree.currentCycle() == currentCycle + 1 console.print("[blue]===== After Retroactive Root =====[/blue]") console.print(rewards["merkleRoot"], rewards["cycle"]) retroactive_claims = rewards["claims"] # Claim as same set of users from previous test with updated root for user, claim in retroactive_claims.items(): # test_claim(badger, user, claim, tokens_to_check) if user in users_to_verify: test_claim(badger, user, claim, tokens_to_check)
def main(): test = True badger = connect_badger(badger_config.prod_json,load_deployer=False) farmTokenAddress = "0xa0246c9032bC3A600820415aE600c6388619A14D" nextCycle = badger.badgerTree.currentCycle() + 1 console.log("next cycle: {}".format(nextCycle)) currentMerkleData = badger.badgerTree.getCurrentMerkleData() console.log(currentMerkleData) timeSinceLastUpdate = chain.time() - currentMerkleData[2] print("Run at", int(time.time())) latestBlock = chain.height harvestEvents = fetch_harvest_farm_events() rewards = RewardsList(nextCycle,badger.badgerTree) console.log(rewards.claims) settStartBlock = 11376266 startBlock = settStartBlock endBlock = int(harvestEvents[0]["blockNumber"]) totalHarvested = 0 for i in tqdm(range(len(harvestEvents))): console.log("Processing between {} and {}".format(startBlock,endBlock)) harvestEvent = harvestEvents[i] user_state = calc_meta_farm_rewards(badger,"harvest.renCrv",startBlock,endBlock) farmRewards = int(harvestEvent["farmToRewards"]) console.print("Processing block {}, distributing {} to users".format( harvestEvent["blockNumber"], farmRewards/1e18, )) totalHarvested += farmRewards/1e18 console.print("{} total FARM processed".format(totalHarvested)) totalShareSeconds = sum([u.shareSeconds for u in user_state]) farmUnit = farmRewards/totalShareSeconds for user in user_state: rewards.increase_user_rewards(web3.toChecksumAddress(user.address),farmTokenAddress,farmUnit * user.shareSeconds) rewardsLogger.add_user_share_seconds(user.address,"harvest.renCrv",user.shareSeconds) rewardsLogger.add_user_token(user.address,"harvest.renCrv",farmTokenAddress,farmUnit* user.shareSeconds) rewardsLogger.add_epoch_data(user_state,"harvest.renCrv",farmTokenAddress,farmUnit,i) if i+1 < len(harvestEvents): startBlock = int(harvestEvent["blockNumber"]) endBlock = int(harvestEvents[i+1]["blockNumber"]) claimsHarvested = sum( [list(v.values())[0] for v in list(rewards.claims.values())]) rewardsLogger.add_distribution_info("harvest.renCrv",{farmTokenAddress:claimsHarvested}) rewardsLogger.save("retroactive-farm") currentRewards = fetch_current_rewards_tree(badger) cumulative_rewards = process_cumulative_rewards(currentRewards,rewards) merkleTree = rewards_to_merkle_tree(cumulative_rewards,settStartBlock,endBlock,{}) # Upload merkle tree rootHash = web3.toHex(web3.keccak(text=merkleTree["merkleRoot"])) console.log(rootHash) contentFileName = "rewards-" + str(chain.id) + "-" + str(merkleTree["merkleRoot"]) + ".json" console.log("Saving merkle tree as {}".format(contentFileName)) with open(contentFileName,"w") as f: json.dump(merkleTree,f,indent=4) farmHarvestedMerkleTree = 0 claims = merkleTree["claims"] for user, claim in claims.items(): if farmTokenAddress in claim["tokens"]: token_index = claim["tokens"].index(farmTokenAddress) amount = claim["cumulativeAmounts"][token_index] console.log("Address {} : {} FARM".format(user,int(float(amount))/1e18)) farmHarvestedMerkleTree += int(float(amount)) console.log("Total Farm Harvested {}".format(farmHarvestedMerkleTree/1e18)) console.log("Claims Harvested From Events {}".format(claimsHarvested/1e18)) console.log("Difference: {}".format((farmHarvestedMerkleTree/1e18) - (claimsHarvested/1e18))) difference = farmHarvestedMerkleTree - claimsHarvested console.log("Difference: {}".format(farmHarvestedMerkleTree - claimsHarvested)) console.log(gas_strategy.get_gas_price()) if abs(difference) < 10000000 and not test: badger.badgerTree.proposeRoot( merkleTree["merkleRoot"], rootHash, nextCycle, {"from" :badger.keeper,"gas_price":gas_strategy}) badger.badgerTree.approveRoot( merkleTree["merkleRoot"], rootHash, nextCycle, {"from" :badger.keeper,"gas_price":gas_strategy})