def rebase(badger: BadgerSystem, account): digg = badger.digg supplyBefore = digg.token.totalSupply() print("spfBefore", digg.token._sharesPerFragment()) print("supplyBefore", digg.token.totalSupply()) print(digg.cpiMedianOracle.getData.call()) sushi = SushiswapSystem() pair = sushi.getPair(digg.token, registry.tokens.wbtc) uni = UniswapSystem() uniPair = uni.getPair(digg.token, registry.tokens.wbtc) last_rebase_time = digg.uFragmentsPolicy.lastRebaseTimestampSec() min_rebase_time = digg.uFragmentsPolicy.minRebaseTimeIntervalSec() in_rebase_window = digg.uFragmentsPolicy.inRebaseWindow() now = chain.time() time_since_last_rebase = now - last_rebase_time min_time_passed = (last_rebase_time + min_rebase_time) < now console.print({ "last_rebase_time": last_rebase_time, "in_rebase_window": in_rebase_window, "now": now, "time_since_last_rebase": time_since_last_rebase, "min_time_passed": min_time_passed, }) # Rebase if sufficient time has passed since last rebase and we are in the window. # Give adequate time between TX attempts if time_since_last_rebase > hours( 2) and in_rebase_window and min_time_passed: console.print( "[bold yellow]===== 📈 Rebase! 📉=====[/bold yellow]") print("pair before", pair.getReserves()) print("uniPair before", uniPair.getReserves()) tx_timer.start_timer(account, "Rebase") tx = digg.orchestrator.rebase({"from": account}) tx_timer.end_timer() if rpc.is_active(): chain.mine() print(tx.call_trace()) print(tx.events) supplyAfter = digg.token.totalSupply() print("spfAfter", digg.token._sharesPerFragment()) print("supplyAfter", supplyAfter) print("supplyChange", supplyAfter / supplyBefore) print("supplyChangeOtherWay", supplyBefore / supplyAfter) print("pair after", pair.getReserves()) print("uniPair after", uniPair.getReserves()) else: console.print("[white]===== No Rebase =====[/white]")
def fetch_params(self): params = sett_config.sushi.sushiDiggWBtc.params sushiswap = SushiswapSystem() # TODO: Pull digg token addr from registry once its deployed. if sushiswap.hasPair(self.digg.token, registry.tokens.wbtc): params.want = sushiswap.getPair(self.digg.token, registry.tokens.wbtc) else: params.want = sushiswap.createPair( self.digg.token, registry.tokens.wbtc, self.deployer, ) want = params.want params.token = self.digg.token params.badgerTree = self.badger.badgerTree self.badger.deploy_logic("DiggRewardsFaucet", DiggRewardsFaucet, test=True) self.rewards = self.badger.deploy_digg_rewards_faucet( self.key, self.digg.token) params.geyser = self.rewards return (params, want)
def distribute_from_whales(recipient, percentage=0.8): console.print( "[green] 🐋 Transferring assets from whales for {} assets... 🐋 [/green]".format( len(whale_registry.items()) ) ) # Normal Transfers for key, whale_config in whale_registry.items(): # Handle special cases after all standard distributions if whale_config.special: continue if key != "_pytestfixturefunction": console.print(" -> {}".format(key)) distribute_from_whale(whale_config, recipient, percentage=0.8) # Special Transfers for key, whale_config in whale_registry.items(): if not whale_config.special: continue if whale_config.action == WhaleRegistryAction.POPULATE_NEW_SUSHI_LP: # Populate LP pair and distribute # NOTE: Account should have been distributed both underlying components previously sushiswap = SushiswapSystem() sushiswap.addMaxLiquidity( whale_config.actionParams["token0"], whale_config.actionParams["token1"], recipient )
def fetch_params(self): params = sett_config.sushi.sushiBadgerWBtc.params sushiswap = SushiswapSystem() want = sushiswap.getPair(self.badger.token, registry.tokens.wbtc) params.want = want params.badgerTree = self.badger.badgerTree params.badger = self.badger.token return (params, want)
def _distributeWant(self, users) -> None: digg = self.manager.badger.digg # Generate lp tokens for users. for user in users: sushiswap = SushiswapSystem() # Generate lp tokens. sushiswap.addMaxLiquidity( digg.token, registry.tokens.wbtc, user, )
def _distributeWant(self, users) -> None: # Generate lp tokens for users. for user in users: # Mint ibBTC using sett lp tokens. self._mintIbBtc(user) sushiswap = SushiswapSystem() # Generate lp tokens. sushiswap.addMaxLiquidity( registry.tokens.ibbtc, registry.tokens.wbtc, user, )
def fetch_params(self): params = sett_config.sushi.sushiWethWBtc.params sushiswap = SushiswapSystem() want = sushiswap.getPair(registry.tokens.weth, registry.tokens.wbtc) assert want == "0xCEfF51756c56CeFFCA006cD410B03FFC46dd3a58" params.want = want params.badgerTree = self.badger.badgerTree params.pid = registry.sushiswap.pids.sushiEthWBtc return (params, want)
def post_vault_deploy_setup(self, deploy=True): """ Setup sushi rewards. """ if not deploy: return # Setup sushi reward allocations. sushiswap = SushiswapSystem() pid = sushiswap.add_chef_rewards(self.want) # Pass in LP token pool id to underlying strategy. self.params.pid = pid
def _distributeWant(self, users) -> None: claw = self.manager.badger.claw # Generate lp tokens for users. for user in users: # Mint some synthetic tokens. claw.mint(user) sushiswap = SushiswapSystem() # Generate lp tokens. sushiswap.addMaxLiquidity( claw.emp.tokenCurrency(), registry.tokens.usdc, user, )
def main(): badger = connect_badger("deploy-final.json") deployer = badger.deployer controller = badger.getController("native") governance = badger.devMultisig strategist = badger.deployer keeper = badger.keeper guardian = badger.guardian for (key, strategyName, isUniswap) in [ ("native.sushiWbtcIbBtc", "StrategySushiLpOptimizer", False), # ("native.uniWbtcIbBtc", "StrategyUniGenericLp", True), ]: if isUniswap: params = sett_config.uni.uniGenericLp.params swap = UniswapSystem() else: params = sett_config.sushi.sushiWbtcIbBtc.params params.badgerTree = badger.badgerTree swap = SushiswapSystem() if swap.hasPair(registry.tokens.ibbtc, registry.tokens.wbtc): params.want = swap.getPair(registry.tokens.ibbtc, registry.tokens.wbtc) else: params.want = swap.createPair( registry.tokens.ibbtc, registry.tokens.wbtc, deployer, ) # NB: Work w/ sushi team to setup sushi reward allocations. vault = badger.deploy_sett( key, params.want, controller, governance=governance, strategist=strategist, keeper=keeper, guardian=guardian, ) time.sleep(sleep_between_tx) strategy = badger.deploy_strategy( key, strategyName, controller, params, governance=governance, strategist=strategist, keeper=keeper, guardian=guardian, ) time.sleep(sleep_between_tx) badger.wire_up_sett(vault, strategy, controller) # TODO: Unpause vault. assert vault.paused()
def fetch_params(self): params = sett_config.sushi.sushiClawUSDC.params sushiswap = SushiswapSystem() token = self.claw.emp.tokenCurrency() if sushiswap.hasPair(token, registry.tokens.usdc): params.want = sushiswap.getPair(token, registry.tokens.usdc) else: params.want = sushiswap.createPair( token, registry.tokens.usdc, self.deployer, ) want = params.want params.badgerTree = self.badger.badgerTree return (params, want)
def deploy_sushi_digg_wbtc_lp_sett(badger, digg): """ If test mode, add initial liquidity and distribute to test user """ deployer = badger.deployer key = "native.sushiDiggWbtc" params = sett_config.sushi.sushiDiggWBtc.params sushiswap = SushiswapSystem() params.want = sushiswap.getPair(digg.token, registry.tokens.wbtc) params.token = digg.token params.badgerTree = badger.badgerTree # params.pid = sushiswap.add_chef_rewards(params.want) # print("pid", params.pid) params.pid = 103 # Deploy Rewards rewards = badger.deploy_digg_rewards_faucet(key, digg.token) params.geyser = rewards time.sleep(sleep_between_tx) deploy_sett_by_key( badger, key, "StrategySushiDiggWbtcLpOptimizer", SettType.DEFAULT, params, deployer=deployer, governance=badger.devMultisig, strategist=badger.deployer, keeper=badger.keeper, guardian=badger.guardian, ) # assert False strategy = badger.getStrategy(key) rewards.grantRole(PAUSER_ROLE, badger.keeper, {"from": deployer}) rewards.grantRole(UNPAUSER_ROLE, badger.devMultisig, {"from": deployer}) # Make strategy the recipient of the DIGG faucet rewards.initializeRecipient(strategy, {"from": deployer})
def fetch_params(self): params = sett_config.sushi.sushiWbtcIbBtc.params sushiswap = SushiswapSystem() if sushiswap.hasPair(registry.tokens.ibbtc, registry.tokens.wbtc): params.want = sushiswap.getPair(registry.tokens.ibbtc, registry.tokens.wbtc) else: params.want = sushiswap.createPair( registry.tokens.ibbtc, registry.tokens.wbtc, self.deployer, ) want = params.want params.badgerTree = self.badger.badgerTree return (params, want)
def main(): badger = connect_badger() table = [] sushi = SushiswapSystem() numPools = sushi.chef.poolLength() for i in range(0, numPools): poolInfo = sushi.chef.poolInfo(i) table.append([poolInfo[0],poolInfo[1],poolInfo[2],poolInfo[3]]) print(tabulate(table, headers=["lpToken", "allocPoint", "lastRewardBlock", "accSushiPerShare"]))
def post_vault_deploy_setup(self, deploy=True): """ Deploy StakingRewardsSignalOnly for Digg Strategy Generate LP tokens and grant to deployer """ if not deploy: return # Setup sushi reward allocations. sushiswap = SushiswapSystem() pid = sushiswap.add_chef_rewards(self.want) # Generate lp tokens. sushiswap.addMaxLiquidity( self.digg.token, registry.tokens.wbtc, self.deployer, ) # Pass in LP token pool id to underlying strategy. self.params.pid = pid
def distribute_from_whales(badger, recipient): console.print( "[green] 🐋 Transferring assets from whales for {} assets... 🐋 [/green]".format( len(whale_registry.items()) ) ) # Normal Transfers for key, whale_config in whale_registry.items(): # Handle special cases after all standard distributions if whale_config.special: continue if key != "_pytestfixturefunction": console.print(" -> {}".format(key)) if whale_config.action == WhaleRegistryAction.DISTRIBUTE_FROM_CONTRACT: forceEther = ForceEther.deploy({"from": recipient}) recipient.transfer(forceEther, Wei("1 ether")) forceEther.forceSend(whale_config.whale, {"from": recipient}) token = interface.IERC20(whale_config.token) token.transfer( recipient, token.balanceOf(whale_config.whale) // 5, {"from": whale_config.whale}, ) # Special Transfers for key, whale_config in whale_registry.items(): if not whale_config.special: continue if whale_config.action == WhaleRegistryAction.POPULATE_NEW_SUSHI_LP: # Populate LP pair and distribute # NOTE: Account should have been distributed both underlying components previously sushiswap = SushiswapSystem() sushiswap.addMaxLiquidity( whale_config.actionParams["token0"], whale_config.actionParams["token1"], recipient )
def main(): badger = connect_badger("deploy-final.json") deployer = badger.deployer key = "native.sushiWbtcIbBtc" controller = badger.getController("native") governance = badger.devMultisig strategist = badger.deployer keeper = badger.keeper guardian = badger.guardian params = sett_config.sushi.sushiWbtcIbBtc.params params.badgerTree = badger.badgerTree sushiswap = SushiswapSystem() if sushiswap.hasPair(registry.tokens.ibbtc, registry.tokens.wbtc): params.want = sushiswap.getPair(registry.tokens.ibbtc, registry.tokens.wbtc) else: params.want = sushiswap.createPair( registry.tokens.ibbtc, registry.tokens.wbtc, deployer, ) # Setup sushi reward allocations (ONLY DO THIS ONCE). params.pid = sushiswap.add_chef_rewards(params.want) vault = badger.deploy_sett( key, params.want, controller, governance=governance, strategist=strategist, keeper=keeper, guardian=guardian, ) time.sleep(sleep_between_tx) strategy = badger.deploy_strategy( key, strategyName, controller, params, governance=governance, strategist=strategist, keeper=keeper, guardian=guardian, ) time.sleep(sleep_between_tx) badger.wire_up_sett(vault, strategy, controller) assert vault.paused() vault.unpause({"from": governance}) assert vault.paused() == False
def _distributeWant(self, users) -> None: # Turn off guestlist. self.core.setGuestList(AddressZero, {"from": self.core.owner()}) # Generate lp tokens for users. for user in users: # Mint ibBTC using sett lp tokens. self._mintIbBtc(user) swap = UniswapSystem() if not self.isUniswap: swap = SushiswapSystem() # Generate lp tokens. swap.addMaxLiquidity( registry.tokens.ibbtc, registry.tokens.wbtc, user, )
def main(): """ Connect to badger, distribute assets to specified test user, and keep ganache open. Ganache will run with your default brownie settings for mainnet-fork """ # The address to test with user = accounts.at(decouple.config("TEST_ACCOUNT"), force=True) badger = connect_badger("deploy-final.json", load_deployer=True, load_keeper=True, load_guardian=True) digg = connect_digg("deploy-final.json") digg.token = digg.uFragments badger.add_existing_digg(digg) console.print( "[blue]=== 🦡 Test ENV for account {} 🦡 ===[/blue]".format(user)) distribute_test_ether(user, Wei("10 ether")) distribute_test_ether(badger.deployer, Wei("20 ether")) distribute_from_whales(user) wbtc = interface.IERC20(token_registry.wbtc) assert wbtc.balanceOf(user) >= 200000000 init_prod_digg(badger, user) accounts.at(digg.daoDiggTimelock, force=True) digg.token.transfer(user, 20000000000, {"from": digg.daoDiggTimelock}) digg_liquidity_amount = 1000000000 wbtc_liquidity_amount = 100000000 assert digg.token.balanceOf(user) >= digg_liquidity_amount * 2 assert wbtc.balanceOf(user) >= wbtc_liquidity_amount * 2 uni = UniswapSystem() wbtc.approve(uni.router, wbtc_liquidity_amount, {"from": user}) digg.token.approve(uni.router, digg_liquidity_amount, {"from": user}) uni.router.addLiquidity( digg.token, wbtc, digg_liquidity_amount, wbtc_liquidity_amount, digg_liquidity_amount, wbtc_liquidity_amount, user, chain.time() + 1000, {"from": user}, ) sushi = SushiswapSystem() wbtc.approve(sushi.router, wbtc_liquidity_amount, {"from": user}) digg.token.approve(sushi.router, digg_liquidity_amount, {"from": user}) sushi.router.addLiquidity( digg.token, wbtc, digg_liquidity_amount, wbtc_liquidity_amount, digg_liquidity_amount, wbtc_liquidity_amount, user, chain.time() + 1000, {"from": user}, ) console.print("[green]=== ✅ Test ENV Setup Complete ✅ ===[/green]") # Keep ganache open until closed time.sleep(days(365))
from helpers.registry import registry from helpers.sett.SnapshotManager import SnapshotManager from helpers.snapshot import diff_numbers_by_key, snap_strategy_balance from helpers.utils import shares_to_fragments, to_digg_shares, to_tabulate, tx_wait from rich.console import Console from scripts.keeper.rapid_harvest import rapid_harvest from scripts.systems.badger_system import BadgerSystem, connect_badger from scripts.systems.digg_system import connect_digg from scripts.systems.sushiswap_system import SushiswapSystem from scripts.systems.uniswap_system import UniswapSystem from tabulate import tabulate gas_strategies.set_default(gas_strategies.exponentialScalingFast) uniswap = UniswapSystem() sushiswap = SushiswapSystem() console = Console() wbtc = interface.IERC20(registry.tokens.wbtc) def lp_for_strategy(badger: BadgerSystem, key): """ Add maximum liquidity for associated strategy LP position """ manager = badger.badgerRewardsManager strategy = badger.getStrategy(key) want = interface.IERC20(strategy.want())
def main(): badger = connect_badger("deploy-final.json") digg = badger.digg tx_data = { "to": "0x8D29bE29923b68abfDD21e541b9374737B49cdAD", "data": "0x8d80ff0a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000009fe00b65cef03b9b89f99517643226d76e286ee999e7700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024694e80c300000000000000000000000000000000000000000000000000000000000000010019d099670a21bc0a8211a89b84cedf59abb4377f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064beabacc80000000000000000000000003472a5a71965499acd81997a54bba8d852c6e53d000000000000000000000000b65cef03b9b89f99517643226d76e286ee999e7700000000000000000000000000000000000000000000017c5d213c7a8f712f400019d099670a21bc0a8211a89b84cedf59abb4377f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064beabacc8000000000000000000000000798d1be841a82a273720ce31c822c61a67a601c3000000000000000000000000b65cef03b9b89f99517643226d76e286ee999e7700000000000000000000000000000000000000000000000000000001b69e2595003472a5a71965499acd81997a54bba8d852c6e53d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044095ea7b3000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f000000000000000000000000000000000000000000000068bce40cf18444c28000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001244a25d94a000000000000000000000000000000000000000000000002b01ee2a20a8a2a90000000000000000000000000000000000000000000000068bce40cf18444c28000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000b65cef03b9b89f99517643226d76e286ee999e7700000000000000000000000000000000000000000000000000000000604be4d100000000000000000000000000000000000000000000000000000000000000030000000000000000000000003472a5a71965499acd81997a54bba8d852c6e53d0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2003472a5a71965499acd81997a54bba8d852c6e53d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044095ea7b300000000000000000000000019d97d8fa813ee2f51ad4b4e04ea08baf4dffc28000000000000000000000000000000000000000000000113a03d2f890b2c6cc00019d97d8fa813ee2f51ad4b4e04ea08baf4dffc2800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024b6b55f25000000000000000000000000000000000000000000000113a03d2f890b2c6cc000798d1be841a82a273720ce31c822c61a67a601c300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044095ea7b30000000000000000000000007e7e112a68d8d2e221e11047a72ffc1065c38e1a00000000000000000000000000000000000000000000000000000001b69e2595007e7e112a68d8d2e221e11047a72ffc1065c38e1a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000246c361865000000000000000000000000b65cef03b9b89f99517643226d76e286ee999e77007e7e112a68d8d2e221e11047a72ffc1065c38e1a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024b6b55f2500000000000000000000000000000000000000000000000000000001b69e25950019d97d8fa813ee2f51ad4b4e04ea08baf4dffc2800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044095ea7b3000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f0000000000000000000000000000000000000000000000e203f5dc3c00323a8000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f00000000000000000000000000000000000000000000000777723ca5ab7fcb9000000000000000000000000000000000000000000000000000000000000000c4f305d71900000000000000000000000019d97d8fa813ee2f51ad4b4e04ea08baf4dffc280000000000000000000000000000000000000000000000e203f5dc3c00323a800000000000000000000000000000000000000000000000e203f5dc3c00323a8000000000000000000000000000000000000000000000000777723ca5ab7fcb90000000000000000000000000b65cef03b9b89f99517643226d76e286ee999e7700000000000000000000000000000000000000000000000000000000604be4db007e7e112a68d8d2e221e11047a72ffc1065c38e1a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044095ea7b3000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f00000000000000000000000000000000000000000000000048ada1feff60844a00d9e1ce17f2641f24ae83637ab66a2cca9c378b9f00000000000000000000000000000000000000000000000777723ca5ab7fcb9000000000000000000000000000000000000000000000000000000000000000c4f305d7190000000000000000000000007e7e112a68d8d2e221e11047a72ffc1065c38e1a00000000000000000000000000000000000000000000000048ada1feff60844a00000000000000000000000000000000000000000000000048ada1feff60844a00000000000000000000000000000000000000000000000777723ca5ab7fcb90000000000000000000000000b65cef03b9b89f99517643226d76e286ee999e7700000000000000000000000000000000000000000000000000000000604be4dd0000", } sushiBbadgerPair = "0x0a54d4b378c8dbfc7bc93be50c85debafdb87439" sushiBDiggPair = "0xf9440fedc72a0b8030861dcdac39a75b544e7a3c" sushiswap = SushiswapSystem() pair = interface.IUniswapV2Pair(sushiBbadgerPair) console.print({ "getReserves": pair.getReserves(), "token0": pair.token0(), "token1": pair.token1(), "price0CumulativeLast": pair.price0CumulativeLast(), "price1CumulativeLast": pair.price1CumulativeLast(), }) pair = interface.IUniswapV2Pair(sushiBDiggPair) console.print({ "getReserves": pair.getReserves(), "token0": pair.token0(), "token1": pair.token1(), "price0CumulativeLast": pair.price0CumulativeLast(), "price1CumulativeLast": pair.price1CumulativeLast(), }) usd_amount = 500000 weth = interface.IERC20(registry.tokens.weth) console.log("..Before Safe") safe = ApeSafe(badger.devMultisig.address) ops_safe = ApeSafe(badger.opsMultisig.address) console.log("..After Safe Setup") # multi = GnosisSafe(badger.devMultisig) # multi.execute( # MultisigTxMetadata(description="Run TX"), # {"to": tx_data["to"], "data": tx_data["data"], "operation": 1}, # ) after = get_token_balances( [ badger.token, digg.token, interface.IERC20(registry.tokens.usdc), interface.IERC20(sushiBbadgerPair), interface.IERC20(sushiBDiggPair), ], [badger.devMultisig], ) after.print() pair = interface.IUniswapV2Pair(sushiBbadgerPair) console.print({ "getReserves": pair.getReserves(), "token0": pair.token0(), "token1": pair.token1(), "price0CumulativeLast": pair.price0CumulativeLast(), "price1CumulativeLast": pair.price1CumulativeLast(), }) pair = interface.IUniswapV2Pair(sushiBDiggPair) console.print({ "getReserves": pair.getReserves(), "token0": pair.token0(), "token1": pair.token1(), "price0CumulativeLast": pair.price0CumulativeLast(), "price1CumulativeLast": pair.price1CumulativeLast(), }) router = safe.contract(sushiswap.router.address) rewardsEscrow = safe.contract(badger.rewardsEscrow.address) badgerToken = safe.contract(badger.token.address) diggToken = safe.contract(digg.token.address) digg_to_lp = Wei("8.4 gwei") usd_per_side = 250000 # TODO: Use banteg's nice value calc script. badger_usd = fetch_usd_price(badger.token.address) digg_usd = fetch_usd_price(digg.token.address) eth_usd = fetch_usd_price_eth() console.log(eth_usd) badger_to_swap = Wei(str(95000 / badger_usd) + " ether") badger_to_lp = Wei(str(usd_per_side / badger_usd) + " ether") digg_to_lp = Wei(str(usd_per_side / digg_usd) + " gwei") eth_out = Wei(str(usd_per_side / eth_usd) + " ether") console.print({ "badger_to_swap": badger_to_swap, "badger_to_lp": badger_to_lp, "digg_to_lp": digg_to_lp, "eth_out": eth_out, "badger_usd": badger_usd, "digg_usd": digg_usd, "eth_usd": eth_usd, }) badger_to_get_from_escrow = badger_to_swap + badger_to_lp # Get 250k worth of bBadger + $90k Amount to swap to ETH rewardsEscrow.transfer(badger.token, badger.devMultisig, badger_to_get_from_escrow) # Get 250k worth of bDigg rewardsEscrow.transfer(digg.token, badger.devMultisig, digg_to_lp) # Sell badger for 90k USD exact_eth = Wei(str(90000 / eth_usd) + " ether") console.print("exact_eth", exact_eth) assert badger.token.balanceOf(badger.devMultisig) >= badger_to_swap print("a") badgerToken.approve(sushiswap.router.address, badger_to_swap) print("b") assert (badger.token.allowance(badger.devMultisig, sushiswap.router.address) == badger_to_swap) router.swapTokensForExactETH( exact_eth, int(badger_to_swap * 1.02), [badger.token, registry.tokens.wbtc, registry.tokens.weth], badger.devMultisig, chain.time() + 200000, ) print("d") after = get_token_balances([badger.token, digg.token], [badger.devMultisig]) after.print() # Deposit Badger for bBadger # Deposit DIGG for bDigg bBadger_address = badger.getSett("native.badger").address bDigg_address = badger.getSett("native.digg").address console.print(bBadger_address, bDigg_address) abi = Sett.abi bBadger = safe.contract_from_abi(bBadger_address, "Sett", abi) bDigg = safe.contract_from_abi(bDigg_address, "Sett", abi) badgerToken.approve(bBadger.address, badger_to_lp) print(bBadger) console.print(bBadger) bBadger.deposit(badger_to_lp) diggToken.approve(bDigg.address, digg_to_lp) bDigg.approveContractAccess(badger.devMultisig) tx = bDigg.deposit(digg_to_lp) console.print(tx.events) # tx = bDigg.withdraw(bDigg.balanceOf(badger.devMultisig)) # console.print(tx.events) after = get_token_balances( [ badger.token, digg.token, interface.IERC20(bDigg.address), interface.IERC20(bBadger.address), ], [badger.devMultisig], ) after.print() # Seed pools: 250k worth of bToken, 250k worth of ETH tokenA = bBadger amountA = (badger_to_lp * 10**18) / bBadger.getPricePerFullShare() amountB = eth_out # TODO: Set the amount of ETH to what is required. after = get_token_balances( [ badger.token, digg.token, interface.IERC20(bDigg.address), interface.IERC20(bBadger.address), interface.IERC20(sushiBbadgerPair), interface.IERC20(sushiBDiggPair), ], [badger.devMultisig], ) after.print() safe_tx = safe.multisend_from_receipts() safe.preview(safe_tx) data = safe.print_transaction(safe_tx) safe.post_transaction(safe_tx) """ How do we get exactly 250k worth of each asset? Calculate how much you need to get 250k ===== Normal Assets ===== 250k / USD price of asset ===== For bTokens ===== How much original token to get: 250k / USD price of underlying asset bToken will handle itself """ tokenA.approve(sushiswap.router, amountA) console.print( "addLiquidityETH", { "tokenA": tokenA.address, "amountA": amountA, "amountB": amountB, "badger ppfs": bBadger.getPricePerFullShare(), "original supply": Wei("4000 gwei"), "current supply": digg.token.totalSupply(), }, ) router.addLiquidityETH( tokenA.address, amountA, int(amountA * 0.95), int(eth_out * 0.95), badger.devMultisig, chain.time() + 200000, {"value": eth_out}, ) tokenA = bDigg amountA = ((digg_to_lp * 10**9) * 10**18) / bDigg.getPricePerFullShare() amountA = amountA * (Wei("4000 gwei")) / digg.token.totalSupply() print("expected bDigg", amountA) amountA = bDigg.balanceOf(badger.devMultisig) print("actual bDigg", amountA) tokenA.approve(sushiswap.router, amountA) console.print( "addLiquidityETH", { "tokenA": tokenA.address, "amountA": amountA, "amountB": amountB, "digg ppfs": bDigg.getPricePerFullShare(), }, ) router.addLiquidityETH( tokenA.address, amountA, int(amountA * 0.95), int(eth_out * 0.95), badger.devMultisig, chain.time() + 200000, {"value": eth_out}, ) after = get_token_balances( [ badger.token, digg.token, interface.IERC20(bDigg.address), interface.IERC20(bBadger.address), interface.IERC20(sushiBbadgerPair), interface.IERC20(sushiBDiggPair), ], [badger.devMultisig], ) after.print() safe_tx = safe.multisend_from_receipts() safe.preview(safe_tx) data = safe.print_transaction(safe_tx) safe.post_transaction(safe_tx) pair = interface.IUniswapV2Pair(sushiBbadgerPair) console.print({ "getReserves": pair.getReserves(), "token0": pair.token0(), "token1": pair.token1(), "price0CumulativeLast": pair.price0CumulativeLast(), "price1CumulativeLast": pair.price1CumulativeLast(), }) pair = interface.IUniswapV2Pair(sushiBDiggPair) console.print({ "getReserves": pair.getReserves(), "token0": pair.token0(), "token1": pair.token1(), "price0CumulativeLast": pair.price0CumulativeLast(), "price1CumulativeLast": pair.price1CumulativeLast(), }) safe.post_transaction(safe_tx) pair = interface.IUniswapV2Pair(sushiBbadgerPair) console.print({ "getReserves": pair.getReserves(), "token0": pair.token0(), "token1": pair.token1(), "price0CumulativeLast": pair.price0CumulativeLast(), "price1CumulativeLast": pair.price1CumulativeLast(), }) pair = interface.IUniswapV2Pair(sushiBDiggPair) console.print({ "getReserves": pair.getReserves(), "token0": pair.token0(), "token1": pair.token1(), "price0CumulativeLast": pair.price0CumulativeLast(), "price1CumulativeLast": pair.price1CumulativeLast(), })
def main(): """ Connect to badger system, and configure multisig for running transactions in local fork without access to accounts """ # Connect badger system from file badger = connect_badger() digg = badger.digg # Sanity check file addresses expectedMultisig = "0xB65cef03b9B89f99517643226d76e286ee999e77" assert badger.devMultisig == expectedMultisig if rpc.is_active(): distribute_test_ether(badger.devMultisig, Wei("5 ether")) # Multisig wrapper # Get price data from sushiswap, uniswap, and coingecko digg_usd_coingecko = 41531.72 btc_usd_coingecko = 32601.13 digg_per_btc = digg_usd_coingecko / btc_usd_coingecko uniTWAP = get_average_daily_price("scripts/oracle/data/uni_digg_hour") sushiTWAP = get_average_daily_price("scripts/oracle/data/sushi_digg_hour") averageTWAP = Average([uniTWAP, sushiTWAP]) console.print({ "uniTWAP": uniTWAP, "sushiTWAP": sushiTWAP, "averageTWAP": averageTWAP }) supplyBefore = digg.token.totalSupply() print("spfBefore", digg.token._sharesPerFragment()) print("supplyBefore", digg.token.totalSupply()) marketValue = Wei(str(averageTWAP) + " ether") print(marketValue) print(int(marketValue * 10**18)) print("digg_per_btc", digg_per_btc, averageTWAP, marketValue) if rpc.is_active(): distribute_test_ether(digg.centralizedOracle, Wei("5 ether")) centralizedMulti = GnosisSafe(digg.centralizedOracle) print(digg.marketMedianOracle.providerReports(digg.centralizedOracle, 0)) print(digg.marketMedianOracle.providerReports(digg.centralizedOracle, 1)) print(digg.cpiMedianOracle.providerReports(digg.constantOracle, 0)) print(digg.cpiMedianOracle.providerReports(digg.constantOracle, 1)) print(digg.cpiMedianOracle.getData.call()) sushi = SushiswapSystem() pair = sushi.getPair(digg.token, registry.tokens.wbtc) uni = UniswapSystem() uniPair = uni.getPair(digg.token, registry.tokens.wbtc) print("pair before", pair.getReserves()) print("uniPair before", uniPair.getReserves()) tx = centralizedMulti.execute( MultisigTxMetadata(description="Set Market Data"), { "to": digg.marketMedianOracle.address, "data": digg.marketMedianOracle.pushReport.encode_input(marketValue), }, ) chain.mine() print(tx.call_trace()) print(tx.events) chain.sleep(hours(0.4)) chain.mine() in_rebase_window = digg.uFragmentsPolicy.inRebaseWindow() while not in_rebase_window: print("Not in rebase window...") chain.sleep(hours(0.1)) chain.mine() in_rebase_window = digg.uFragmentsPolicy.inRebaseWindow() tx = digg.orchestrator.rebase({"from": accounts[0]}) chain.mine() supplyAfter = digg.token.totalSupply() print("spfAfter", digg.token._sharesPerFragment()) print("supplyAfter", supplyAfter) print("supplyChange", supplyAfter / supplyBefore) print("supplyChangeOtherWay", supplyBefore / supplyAfter) print("pair after", pair.getReserves()) print("uniPair after", uniPair.getReserves())