def rapid_harvest(badger): """ Atomically transfer and deposit tokens from rewards manager to associated strategies Requires that LP positons are swapped """ # TODO: Output message when failure # TODO: Use test mode if RPC active, no otherwise rewards = get_active_rewards_schedule(badger) digg = badger.digg manager = badger.badgerRewardsManager if rpc.is_active(): """ Test: Load up sending accounts with ETH and whale tokens """ accounts[0].transfer(badger.deployer, Wei("5 ether")) accounts[0].transfer(badger.external_harvester, Wei("5 ether")) accounts[0].transfer(badger.guardian, Wei("5 ether")) # TODO: Daily amount = calculate from the LP token scale # # ===== native.uniBadgerWbtc ===== key = "native.uniBadgerWbtc" want = badger.getStrategyWant(key) transfer_for_strategy(badger, key, want.balanceOf(manager)) # # # ===== native.sushiBadgerWbtc ===== key = "native.sushiBadgerWbtc" want = badger.getStrategyWant(key) transfer_for_strategy(badger, key, want.balanceOf(manager)) # # # ===== native.uniDiggWbtc ===== key = "native.uniDiggWbtc" want = badger.getStrategyWant(key) transfer_for_strategy(badger, key, want.balanceOf(manager)) # # # ===== native.sushiDiggWbtc ===== key = "native.sushiDiggWbtc" want = badger.getStrategyWant(key) transfer_for_strategy(badger, key, want.balanceOf(manager)) # ===== native.badger ===== key = "native.badger" # TODO: Specify actual amounts here transfer_for_strategy( badger, key, rewards.getDistributions(key).getToStakingRewardsDaily("badger")) # ===== native.digg ===== key = "native.digg" diggBaseRewards = shares_to_fragments( rewards.getDistributions(key).getToStakingRewardsDaily("digg")) transfer_for_strategy( badger, key, diggBaseRewards, decimals=9, )
def print_logger_unlock_schedules(self, beneficiary, name=None): logger = self.rewardsLogger schedules = logger.getAllUnlockSchedulesFor(beneficiary) if not name: name = "" console.print(f"[cyan]=== Latest Unlock Schedules {name}===[/cyan]") table = [] if len(schedules) == 0: return for schedule in schedules: print(schedule) s = LoggerUnlockSchedule(schedule) digg_shares = s.token == self.digg.token if digg_shares: scaled = shares_to_fragments(s.amount) else: scaled = val(amount=s.amount, token=s.token) table.append([ name, s.beneficiary, s.token, scaled, to_days(s.duration), to_utc_date(s.start), to_utc_date(s.end), "{:.0f}".format(s.start), "{:.0f}".format(s.end), ]) print( tabulate( table, headers=[ "name", "beneficiary", "token", "amount", "duration", "start", "end", "start", "end", ], )) print("\n")
def print_latest_unlock_schedules(self, geyser, name=None): if not name: name = "" console.print(f"[cyan]=== Latest Unlock Schedules {name}===[/cyan]") table = [] tokens = geyser.getDistributionTokens() for token in tokens: schedules = geyser.getUnlockSchedulesFor(token) num_schedules = geyser.unlockScheduleCount(token) if num_schedules == 0: continue last_schedule = num_schedules - 1 s = UnlockSchedule(token, schedules[last_schedule]) digg_shares = token == self.digg.token if digg_shares: scaled = shares_to_fragments(s.amount) else: scaled = val(amount=s.amount, token=token) table.append([ name, token, scaled, to_days(s.duration), to_utc_date(s.start), to_utc_date(s.end), "{:.0f}".format(s.start), "{:.0f}".format(s.end), ]) print( tabulate( table, headers=[ "geyser", "token", "amount", "duration", "start", "end", "start", "end", ], )) print("\n")
def main(): badger = connect_badger("deploy-final.json") admin = badger.devProxyAdmin multisig = badger.devMultisig contracts = badger.contracts_upgradeable deployer = badger.deployer expectedMultisig = "0xB65cef03b9B89f99517643226d76e286ee999e77" assert multisig == expectedMultisig rest = get_active_rewards_schedule(badger) rest.printState("Week ?? - who knows anymore") recipient = accounts.at(expectedMultisig, force=True) # rest.transfer(badger.token, 33038371371007690000000, recipient) # rest.transfer(badger.digg.token, Wei("3 gwei"), badger.treasuryMultisig) rest.testTransactions() console.print(rest.totals) console.print(shares_to_fragments(rest.totals["digg"]))
def printState(self, title): console.print( "\n[yellow]=== 🦡 Rewards Schedule: {} 🦡 ===[/yellow]".format( title)) table = [] rewardsEscrow = self.badger.rewardsEscrow for key, dist in self.distributions.items(): if key == "native.digg": continue print(key, dist) geyser = self.badger.getGeyser(key) print(geyser) assert rewardsEscrow.isApproved(geyser) for asset, value in dist.toGeyser.items(): """ function signalTokenLock( address geyser, address token, uint256 amount, uint256 durationSec, uint256 startTime ) """ encoded = rewardsEscrow.signalTokenLock.encode_input( geyser, asset_to_address(asset), value, self.duration, self.start) asset_contract = interface.IERC20(asset_to_address(asset)) scaled = val(value, decimals=18) if asset == "digg": scaled = val(shares_to_fragments(value), decimals=9) table.append([ key, # geyser, asset, value, scaled, to_utc_date(self.start), to_utc_date(self.end), to_days(self.duration), # geyser.address, # encoded, ]) print( tabulate( table, headers=[ "key", # "geyser", "token", "total amount", "scaled amount", "start time", "end time", "duration", # "rate per day", # "destination", # "encoded call", ], tablefmt="rst", )) print("total distributed for {}: ".format(asset), val(self.totals[asset]))
def main(): """ Swap daily allowance for LP tokens & run injection harvest """ badger = connect_badger(load_external_harvester=True) rewards = get_active_rewards_schedule(badger) if rpc.is_active(): """ Test: Load up sending accounts with ETH and whale tokens """ accounts[0].transfer(badger.deployer, Wei("5 ether")) accounts[0].transfer(badger.external_harvester, Wei("5 ether")) accounts[0].transfer(badger.guardian, Wei("5 ether")) # swap one day of tokens manager = badger.badgerRewardsManager # # ===== native.uniBadgerWbtc ===== key = "native.uniBadgerWbtc" swap_for_strategy( badger, key, rewards.getDistributions(key).getToStakingRewardsDaily("badger") // 2, ) lp_for_strategy(badger, key) # ===== native.sushiBadgerWbtc ===== key = "native.sushiBadgerWbtc" swap_for_strategy( badger, key, rewards.getDistributions(key).getToStakingRewardsDaily("badger") // 2, ) lp_for_strategy(badger, key) # # ===== native.uniDiggWbtc ===== key = "native.uniDiggWbtc" swap_for_strategy( badger, key, shares_to_fragments( rewards.getDistributions(key).getToStakingRewardsDaily("digg") // 2), ) lp_for_strategy(badger, key) # # ===== native.sushiDiggWbtc ===== key = "native.sushiDiggWbtc" swap_for_strategy( badger, key, shares_to_fragments( rewards.getDistributions(key).getToStakingRewardsDaily("digg") // 2), ) lp_for_strategy(badger, key) rapid_harvest(badger)
def main(): badger = connect_badger(badger_config.prod_json) rewards = get_active_rewards_schedule(badger) b1 = rewards.getDistributions( "native.uniBadgerWbtc").getToStakingRewardsDaily("badger") * 5 b2 = rewards.getDistributions( "native.sushiBadgerWbtc").getToStakingRewardsDaily("badger") * 5 b3 = rewards.getDistributions("native.badger").getToStakingRewardsDaily( "badger") * 5 total_badger = b1 + b2 + b3 d1 = shares_to_fragments( rewards.getDistributions( "native.uniDiggWbtc").getToStakingRewardsDaily("digg")) * 5 d2 = shares_to_fragments( rewards.getDistributions( "native.sushiDiggWbtc").getToStakingRewardsDaily("digg")) * 5 d3 = shares_to_fragments( rewards.getDistributions("native.digg").getToStakingRewardsDaily( "digg")) * 6 total_digg = d1 + d2 + d3 table = [] table.append(["native.uniBadgerWbtc", val(b1)]) table.append(["native.sushiBadgerWbtc", val(b2)]) table.append(["native.badger", val(b3)]) table.append(["total badger", val(total_badger)]) print(tabulate(table, headers=["metric", "value"])) table = [] table.append(["native.uniDiggWbtc", val(d1, decimals=9)]) table.append(["native.sushiDiggWbtc", val(d2, decimals=9)]) table.append(["native.digg", val(d3, decimals=9)]) table.append(["total digg", val(total_digg, decimals=9)]) print(tabulate(table, headers=["metric", "value"])) rewards.printState("Geyser Emissions") # Generate Sufficient multi = GnosisSafe(badger.devMultisig) print(badger.badgerRewardsManager) multi.execute( MultisigTxMetadata(description="Transfer Remaining Weekly Badger"), { "to": badger.rewardsEscrow.address, "data": badger.rewardsEscrow.transfer.encode_input( badger.token, badger.badgerRewardsManager, total_badger) }) assert badger.token.balanceOf(badger.badgerRewardsManager) >= total_badger multi.execute( MultisigTxMetadata(description="Transfer Remaining Weekly Badger"), { "to": badger.rewardsEscrow.address, "data": badger.rewardsEscrow.transfer.encode_input( badger.digg.token, badger.badgerRewardsManager, total_digg) }) assert badger.digg.token.balanceOf( badger.badgerRewardsManager) >= total_digg