def calc_sett_rewards(badger, periodStartBlock, endBlock, cycle, unclaimedRewards): """ Calculate rewards for each sett, and sum them """ # ratio = digg_btc_twap(periodStartBlock,endBlock) # diggAllocation = calculate_digg_allocation(ratio) rewardsBySett = {} noRewards = ["native.digg", "experimental.digg"] boosts, boostInfo = badger_boost(badger, endBlock) apyBoosts = {} multiplierData = {} for key, sett in badger.sett_system.vaults.items(): if key in noRewards: continue settRewards, apyBoost = calc_snapshot(badger, key, periodStartBlock, endBlock, cycle, boosts, unclaimedRewards) if len(apyBoost) > 0: minimum = min(apyBoost.values()) maximum = max(apyBoost.values()) multiplierData[sett.address] = {"min": minimum, "max": maximum} for addr in apyBoost: if addr not in apyBoosts: apyBoosts[addr] = {} apyBoosts[addr][sett.address] = apyBoost[addr] rewardsBySett[key] = settRewards rewards = combine_rewards(list(rewardsBySett.values()), cycle, badger.badgerTree) boostsMetadata = {"multiplierData": multiplierData, "userData": {}} for addr, multipliers in apyBoosts.items(): boostsMetadata["userData"][addr] = { "boost": boosts.get(addr, 1), "multipliers": multipliers, "nonNativeBalance": boostInfo.get(addr, {}).get("nonNativeBalance", 0), "nativeBalance": boostInfo.get(addr, {}).get("nativeBalance", 0), "stakeRatio": boostInfo.get(addr, {}).get("stakeRatio", 0), } with open("badger-boosts.json", "w") as fp: json.dump(boostsMetadata, fp) upload_boosts(test=False) return rewards
def calc_all_sushi_rewards(badger, startBlock, endBlock, nextCycle): allSushiEvents = fetch_sushi_harvest_events() wbtcEthRewards = calc_sushi_rewards( badger, startBlock, endBlock, nextCycle, allSushiEvents["wbtcEth"], "native.sushiWbtcEth", ) wbtcBadgerRewards = calc_sushi_rewards( badger, startBlock, endBlock, nextCycle, allSushiEvents["wbtcBadger"], "native.sushiBadgerWbtc", ) wbtcDiggRewards = calc_sushi_rewards( badger, startBlock, endBlock, nextCycle, allSushiEvents["wbtcDigg"], "native.sushiDiggWbtc", ) iBbtcWbtcRewards = calc_sushi_rewards( badger, startBlock, endBlock, nextCycle, allSushiEvents["iBbtcWbtc"], "experimental.sushiIBbtcWbtc", ) # Verify all rewards are correct (for extra safety) return combine_rewards( [wbtcEthRewards, wbtcBadgerRewards, wbtcDiggRewards, iBbtcWbtcRewards], nextCycle, badger.badgerTree, )
def calc_all_sushi_rewards(badger, startBlock, endBlock, nextCycle, retroactive): allSushiEvents = fetch_sushi_harvest_events() wbtcEthRewards = calc_sushi_rewards( badger, startBlock, endBlock, nextCycle, allSushiEvents["wbtcEth"], "native.sushiWbtcEth", retroactive=retroactive, retroactiveStart=11537600, ) wbtcBadgerRewards = calc_sushi_rewards( badger, startBlock, endBlock, nextCycle, allSushiEvents["wbtcBadger"], "native.sushiBadgerWbtc", retroactive=retroactive, retroactiveStart=11539529, ) wbtcDiggRewards = calc_sushi_rewards( badger, startBlock, endBlock, nextCycle, allSushiEvents["wbtcDigg"], "native.sushiDiggWbtc", retroactive=retroactive, retroactiveStart=11676338, ) # Verify all rewards are correct (for extra safety) return combine_rewards( [wbtcEthRewards, wbtcBadgerRewards, wbtcDiggRewards], nextCycle, badger.badgerTree, )
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, }
def generate_rewards_in_range(badger, startBlock, endBlock, pastRewards): endBlock = endBlock 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) settRewards = calc_sett_rewards(badger, startBlock, endBlock, nextCycle) # farmRewards = calc_farm_rewards( # badger, startBlock, endBlock, nextCycle, retroactive=False # ) # sushiRewards = calc_all_sushi_rewards( # badger, startBlock, endBlock, nextCycle, retroactive=False # ) newRewards = combine_rewards([settRewards], 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"]) rewardsLog.set_merkle_root(rootHash) 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) rewardsLog.save("rewards-{}".format(nextCycle)) # 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, }