def main(): badger = connect_badger("deploy-final.json") digg = badger.digg admin = badger.devProxyAdmin multisig = badger.devMultisig contracts = badger.contracts_upgradeable deployer = badger.deployer expectedMultisig = "0xB65cef03b9B89f99517643226d76e286ee999e77" assert multisig == expectedMultisig safe = ApeSafe(badger.devMultisig.address) abi = Sett.abi diggToken = safe.contract(digg.token.address) bDigg = safe.contract_from_abi( badger.getSett("native.digg").address, "Sett", abi) rewardsEscrow = safe.contract_from_abi(badger.rewardsEscrow.address, "RewardsEscrow", RewardsEscrow.abi) teamVesting = safe.contract(badger.teamVesting.address) voting = safe.contract_from_abi(badger.daoBadgerTimelock.address, "IVoting", interface.IVoting.abi) aragon = AragonSystem() aragonVoting = aragon.getVotingAt( web3.toChecksumAddress("0xdc344bfb12522bf3fa58ef0d6b9a41256fc79a1b")) token_registry = registry.token_system() dev = accounts.at(badger.devMultisig.address, force=True) tokens = [ token_registry.erc20_by_address(registry.tokens.farm), token_registry.erc20_by_address(registry.tokens.xSushi), token_registry.erc20_by_address(registry.curve.pools.sbtcCrv.token), token_registry.erc20_by_address(registry.curve.pools.renCrv.token), token_registry.erc20_by_address(registry.curve.pools.tbtcCrv.token), token_registry.erc20_by_address(registry.sushi.lpTokens.sushiWbtcWeth), token_registry.erc20_by_address(registry.tokens.dfd), ] snap = BalanceSnapshotter(tokens, [badger.devMultisig, badger.dao.agent]) snap.snap(name="Before Transfers") for id in vote_ids: voting.vote(id, True, True) rewardsEscrow.call(aragonVoting, 0, aragonVoting.vote.encode_input(id, True, True)) teamVesting.call(aragonVoting, 0, aragonVoting.vote.encode_input(id, True, True)) snap.snap(name="After Transfers") snap.diff_last_two() safe_tx = safe.multisend_from_receipts() safe.preview(safe_tx) data = safe.print_transaction(safe_tx) safe.post_transaction(safe_tx)
def main(): badger = connect_badger() digg = badger.digg safe = ApeSafe(badger.devMultisig.address) abi = Sett.abi badgerToken = safe.contract(badger.token.address) diggToken = safe.contract(digg.token.address) bBadger = safe.contract_from_abi( badger.getSett("native.badger").address, "Sett", abi) bDigg = safe.contract_from_abi( badger.getSett("native.digg").address, "Sett", abi) rewardsEscrow = safe.contract(badger.rewardsEscrow.address) # Exchange renBTC for wBTC wbtc = tokens.erc20_by_key("wbtc") renbtc = tokens.erc20_by_key("renbtc") snap = BalanceSnapshotter([wbtc, renbtc], [badger.devMultisig]) snap.snap(name="Before", print=True) crv_swap(badger, safe, amount_in=367606868, max_slippage=0.005) snap.snap(name="After") snap.diff_last_two() helper = ApeSafeHelper(badger, safe) helper.publish()
def main(): """ First, swap half of the USDC into DAI Deposit USDC portion in to Yearn USDC Vault V2 Deposit DAI portion in to Yearn DAI Vault V2 For the deposits, create small test transactions first """ badger = connect_badger() safe = ApeSafe(badger.paymentsMultisig.address) helper = ApeSafeHelper(badger, safe) # Fetch tokens for snap + interactions usdc = safe.contract("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48") dai = safe.contract("0x6B175474E89094C44Da98b954EedeAC495271d0F") yDai = safe.contract("0x19D3364A399d251E894aC732651be8B0E4e85001") yUsdc = safe.contract("0x5f18C75AbDAe578b483E5F43f12a39cF75b973a9") usdc_to_swap = 35000 * 10**6 ## 1.5 * 10^6 (Million) * 10^6 (Decimals) # TODO: Track the balances of the tokens representing your position here: AAVE USDC (aUSDC), Compound USDC (cUSDC), y3Crv Vault Position (y3Crv) snap = BalanceSnapshotter( [usdc, dai, yDai, yUsdc], [ badger.paymentsMultisig, ], ) snap.snap() current_dai_balance = dai.balanceOf(badger.devMultisig.address) ## NOTE: Swap to DAI with Curve ## Coins[0] == DAI ## Coins[1] == UDC curve_pool = safe.contract("0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7") dai_out = curve_pool.get_dy(1, 0, usdc_to_swap) with_slippage = dai_out * 0.99 print("With slippage") print(with_slippage) usdc.approve(curve_pool.address, usdc_to_swap) curve_pool.exchange(1, 0, usdc_to_swap, with_slippage) post_swap_balance = dai.balanceOf(badger.devMultisig.address) dai_to_deposit = post_swap_balance - current_dai_balance print("dai_to_deposit") print(dai_to_deposit) chain.sleep(10) chain.mine() snap.snap() snap.diff_last_two() ## Publish all Txs helper.publish()
def main(): badger = connect_badger("deploy-final.json") digg = badger.digg admin = badger.devProxyAdmin multisig = badger.devMultisig contracts = badger.contracts_upgradeable deployer = badger.deployer expectedMultisig = "0xB65cef03b9B89f99517643226d76e286ee999e77" assert multisig == expectedMultisig safe = ApeSafe(badger.devMultisig.address) abi = Sett.abi diggToken = safe.contract(digg.token.address) bDigg = safe.contract_from_abi( badger.getSett("native.digg").address, "Sett", abi) rewardsEscrow = safe.contract(badger.rewardsEscrow.address) snap = BalanceSnapshotter( [diggToken, bDigg], [badger.devMultisig, badger.deployer, badger.rewardsEscrow]) snap.snap(name="Before Transfers") ppfs = bDigg.getPricePerFullShare() digg_to_deposit = 10 * (10**18) // (10**9) console.print("digg_to_deposit", digg_to_deposit, ppfs) # Transfer assets to multisig rewardsEscrow.transfer(diggToken, badger.devMultisig, digg_to_deposit) snap.snap(name="After Transfers") snap.diff_last_two() # Deposit bDigg diggToken.approve(bDigg.address, digg_to_deposit) tx = bDigg.deposit(digg_to_deposit) print(tx.events) snap.snap(name="After Deposits") snap.diff_last_two() safe_tx = safe.multisend_from_receipts() safe.preview(safe_tx) data = safe.print_transaction(safe_tx) safe.post_transaction(safe_tx)
def main(): """ Transfer badger to recipient, ensuring they are approved as recipient first Use test tx, full tx model Can convert from dollar value """ badger = connect_badger() multisig = badger.devMultisig safe = ApeSafe(multisig.address) helper = ApeSafeHelper(badger, safe) rewardsEscrow = safe.contract(badger.rewardsEscrow.address) recipient = badger.badgerRewardsManager # token = badger.token # amount = Wei("30000 ether") token = badger.digg.token amount = Wei("2 gwei") if not rewardsEscrow.isApproved(recipient): rewardsEscrow.approveRecipient(recipient) rewardsEscrow.transfer(token, recipient, amount) helper.publish()
def main(): badger = connect_badger("deploy-final.json") digg = badger.digg admin = badger.devProxyAdmin multisig = badger.devMultisig contracts = badger.contracts_upgradeable deployer = badger.deployer expectedMultisig = "0xB65cef03b9B89f99517643226d76e286ee999e77" assert multisig == expectedMultisig recipient = accounts.at("0x8Ea8a668f89a9A203d37D8a1E27e38De5bEb8380", force=True) safe = ApeSafe(badger.devMultisig.address) abi = Sett.abi badgerToken = safe.contract(badger.token.address) diggToken = safe.contract(digg.token.address) bBadger = safe.contract_from_abi( badger.getSett("native.badger").address, "Sett", abi) bDigg = safe.contract_from_abi( badger.getSett("native.digg").address, "Sett", abi) snap = BalanceSnapshotter( [badgerToken, diggToken, bBadger, bDigg], [badger.devMultisig, badger.deployer, badger.rewardsEscrow, recipient], ) snap.snap(name="Before Transfers", print=True) bBadger_amount = Wei("4585.501571219566358195 ether") bDigg_amount = Wei("6.96203478522210066 ether") # Transfer receieved amounts to badger deployer for transfer over bridge bBadger.transfer(recipient, bBadger_amount) bDigg.transfer(recipient, bDigg_amount) snap.snap(name="After Transfers") snap.diff_last_two() safe_tx = safe.multisend_from_receipts() safe.preview(safe_tx) data = safe.print_transaction(safe_tx) safe.post_transaction(safe_tx)
def main(): badger = connect_badger() multisig = badger.devMultisig safe = ApeSafe(multisig.address) abi = Sett.abi bBadger = safe.contract_from_abi( badger.getSett("native.badger").address, "Sett", abi ) usdcToken = safe.contract_from_abi( registry.tokens.usdc, "IERC20", interface.IERC20.abi ) badgerToken = safe.contract_from_abi( badger.token.address, "IERC20", interface.IERC20.abi ) wbtcToken = safe.contract_from_abi( registry.tokens.wbtc, "IERC20", interface.IERC20.abi ) rewardsEscrow = safe.contract(badger.rewardsEscrow.address) # TODO: Do this in bBadger going forward - this is the way. # Approve treasury multi to stake # Deposit badger -> bBadger snap = BalanceSnapshotter( [badgerToken, usdcToken, wbtcToken], [multisig, badger.deployer, badger.rewardsEscrow], ) opolis_dest = "0x27657399177403a891CC7A22Bd6F2C00621Db7b0" test_usdc = 1 * 10 ** 6 full_usdc = 499999 * 10 ** 6 full_badger = Wei("10163.59 ether") full_wbtc = 3.805754301 * 10 ** 8 console.print("Sending Amounts") snap.snap(name="Before Transfers") usdcToken.transfer(opolis_dest, full_usdc) rewardsEscrow.approveRecipient(opolis_dest) rewardsEscrow.transfer(badger.token, opolis_dest, full_badger) # badgerToken.transfer(opolis_dest, full_badger) wbtcToken.transfer(opolis_dest, full_wbtc) snap.snap(name="After Transfers") snap.diff_last_two() safe_tx = safe.multisend_from_receipts() safe.preview(safe_tx) data = safe.print_transaction(safe_tx) safe.post_transaction(safe_tx)
def test_main(): """ What contracts are required? Sett (Proxy) GuestList (Proxy) Strategy (Logic + Proxy) What addresses do I need? Fee splitter Mushroom fee address All that good stuff """ badger = connect_badger() digg = badger.digg dev = badger.deployer distribute_from_whales(dev, assets=["digg"]) digg.token.transfer(badger.devMultisig, digg.token.balanceOf(dev), {"from": dev}) multi = GnosisSafe(badger.devMultisig) safe = ApeSafe(badger.devMultisig.address) ops = ApeSafe(badger.opsMultisig.address) helper = ApeSafeHelper(badger, safe) controller = safe.contract("0x9b4efA18c0c6b4822225b81D150f3518160f8609") controller.setVault() """ address _token, address _controller, address _governance, address _keeper, address _guardian, bool _overrideTokenName, string memory _namePrefix, string memory _symbolPrefix """ for i in range(0, len(assets)): asset = interface.IERC20(assets[i]) vault = interface.ISett(vaults[i]) vault.initialize( asset, controller, badger.devMultisig, badger.keeper, badger.guardian, False, "", "", ) controller.setVault(asset, vault)
def crv_swap(badger, safe: ApeSafe, amount_in, max_slippage): wbtc = safe.contract(tokens.erc20_by_key("wbtc").address) renbtc = safe.contract(tokens.erc20_by_key("renbtc").address) indicies = {'wbtc': 1, 'renbtc': 0} # sbtc = interface.ICurveFi("0x7fc77b5c7614e1533320ea6ddc2eb61fa00a9714") sbtc = safe.contract_from_abi(address=web3.toChecksumAddress( "0x7fc77b5c7614e1533320ea6ddc2eb61fa00a9714"), name="ICurveFi", abi=interface.ICurveFi.abi) # wbtc.approve(sbtc, amount_in) renbtc.approve(sbtc, amount_in) required_out = amount_in - int(amount_in * max_slippage) print(required_out) sbtc.exchange(indicies['renbtc'], indicies['wbtc'], amount_in, required_out)
def main(): """ Promote an experimental vault to official status """ key = "experimental.sushiIBbtcWbtc" badger = connect_badger() safe = ApeSafe(badger.devMultisig.address) ops = ApeSafe(badger.opsMultisig.address) experimental_controller = safe.contract( badger.getController("experimental").address ) native_controller = ops.contract(badger.getController("native").address) # Set experimental strategist to ops multisig experimental_controller.setStrategist(badger.opsMultisig) # Move contract upgradability behind timelock admin = ops.contract(badger.opsProxyAdmin.address) sett = ops.contract(badger.getSett("experimental.sushiIBbtcWbtc").address) strategy = ops.contract(badger.getStrategy("experimental.sushiIBbtcWbtc").address) assert badger.getProxyAdmin(sett) == badger.opsProxyAdmin assert badger.getProxyAdmin(strategy) == badger.opsProxyAdmin admin.changeProxyAdmin(sett, badger.devProxyAdmin) admin.changeProxyAdmin(strategy, badger.devProxyAdmin) assert badger.devProxyAdmin.owner() == badger.governanceTimelock # Move Sett to native controller sett.setController(native_controller) native_controller.setVault(sett.token(), sett) native_controller.approveStrategy(sett.token(), strategy) native_controller.setStrategy(sett.token(), strategy) helper = ApeSafeHelper(badger, safe) helper.publish()
def deploy(self, sett_type=SettType.DEFAULT, deploy=True) -> BadgerSystem: badger = connect_badger() digg = badger.digg dev = badger.deployer timelock = badger.digg.daoDiggTimelock multi = GnosisSafe(badger.devMultisig) safe = ApeSafe(badger.devMultisig.address) ops = ApeSafe(badger.opsMultisig.address) bDigg = safe.contract_from_abi( badger.getSett("native.digg").address, "Sett", Sett.abi ) controller = ops.contract(badger.getController("experimental").address) stabilizeVault = "0xE05D2A6b97dce9B8e59ad074c2E4b6D51a24aAe3" diggTreasury = DiggTreasury.deploy({"from": dev}) strategy = StabilizeStrategyDiggV1.deploy({"from": dev}) strategy.initialize( badger.devMultisig, dev, controller, badger.keeper, badger.guardian, 0, [stabilizeVault, diggTreasury], [250, 0, 50, 250], {"from": dev}, ) diggTreasury.initialize(strategy, {"from": dev}) """ address _governance, address _strategist, address _controller, address _keeper, address _guardian, uint256 _lockedUntil, address[2] memory _vaultConfig, uint256[4] memory _feeConfig """ print("governance", controller.governance()) controller.approveStrategy(digg.token, strategy) controller.setStrategy(digg.token, strategy) self.badger = badger return self.badger
def main(): safe = ApeSafe('0xD089cc83f5B803993E266ACEB929e52A993Ca2C8') agent_address = '0x3e40d73eb977dc6a537af587d48316fee66e9c8c' eth_spent = 0 for cover in unslashed_covers: print("Calc cover for ", cover["policy_name"]) eth_to_cover = cover["damage_eth_covered"] if eth_to_cover == 0: continue um = safe.contract(cover["marketAddress"]) ut = interface.ERC20(cover["premiumToken"]) deposit_delta = um.coverToPremiumTokens( eth_to_cover * 1e18) * um.premiumTokenPrice18eRatio() / 1e18 print("Cover for", eth_to_cover, " ETH") print("ETH required to make deposit: ", deposit_delta / 1e18) premium_balance_before = ut.balanceOf(agent_address) um.depositPremium({'value': deposit_delta}) premium_balance_after = ut.balanceOf(agent_address) print("Premium tokens delta: ", (premium_balance_after - premium_balance_before) / 1e18) print("Premium tokens balance after: ", (premium_balance_after) / 1e18) print("ETH amount", Wei(deposit_delta), deposit_delta / 1e18) eth_spent += deposit_delta print("total ETH to spend", eth_spent / 1e18) safe_tx = safe.multisend_from_receipts() print("safe tx preview:") safe.preview(safe_tx) sys.stdout.write('Are you sure (y/n)? ') if not prompt_bool(): print('Aborting') return safe.post_transaction(safe_tx) print("safe tx sent!")
def main(): badger = connect_badger(load_deployer=True) admin = badger.devProxyAdmin multisig = badger.devMultisig contracts = badger.contracts_upgradeable deployer = badger.deployer safe = ApeSafe(badger.opsMultisig.address) logger = safe.contract(badger.rewardsLogger.address) experimental_vault = "0x8a8ffec8f4a0c8c9585da95d9d97e8cd6de273de" start = 1620943200 duration = days(7) end = start + duration badger_amount = int(Wei("4000 ether") * .9) digg_amount = int(fragments_to_shares(0.4) * .9) dfd_amount = int(Wei("205131 ether") * .9) schedules = [ LoggerUnlockSchedule((experimental_vault, badger.token.address, badger_amount, start, end, duration)), LoggerUnlockSchedule((experimental_vault, badger.digg.token.address, digg_amount, start, end, duration)), LoggerUnlockSchedule((experimental_vault, registry.tokens.dfd, dfd_amount, start, end, duration)) ] for i in range(0, len(schedules)): schedule = schedules[i] logger.setUnlockSchedule( schedule.beneficiary, schedule.token, schedule.amount, schedule.start, schedule.end, schedule.duration ) badger.print_logger_unlock_schedules(experimental_vault, name="Experimental iBBTC Vault") helper = ApeSafeHelper(badger, safe) helper.publish()
def main(): safe_address = '0xD089cc83f5B803993E266ACEB929e52A993Ca2C8' safe = ApeSafe(safe_address) agent_address = '0x3e40d73eb977dc6a537af587d48316fee66e9c8c' should_send = False for cover in unslashed_covers: request_tokens = interface.ERC20(cover["premiumToken"]) ut = safe.contract(cover["premiumToken"]) balance = request_tokens.balanceOf(safe_address) if balance > 0: print('got tokens', balance, cover["premiumToken"], ut.balanceOf(safe_address)) ut.transfer(agent_address, balance, {'gas_limit': 100000}) should_send = True safe_tx = safe.multisend_from_receipts() print('gas', safe.estimate_gas(safe_tx)) if not should_send: print("nothing to send to agent!") return print("safe tx preview:") safe.preview(safe_tx) sys.stdout.write('Are you sure (y/n)? ') if not prompt_bool(): print('Aborting') return safe.post_transaction(safe_tx)
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(): badger = connect_badger() digg = badger.digg safe = ApeSafe(badger.paymentsMultisig.address) abi = Sett.abi badgerToken = safe.contract(badger.token.address) diggToken = safe.contract(digg.token.address) bBadger = safe.contract_from_abi( badger.getSett("native.badger").address, "Sett", abi) bDigg = safe.contract_from_abi( badger.getSett("native.digg").address, "Sett", abi) rewardsEscrow = safe.contract(badger.rewardsEscrow.address) badger_usd = fetch_usd_price(badger.token.address) eth_usd = fetch_usd_price_eth() # USD Denominated # badger_to_send = Wei(str(total_usd / badger_usd) + " ether") # Badger Denominated badger_to_send = Wei("5970.744318 ether") table = [] table.append(["badger", badger_to_send, badger_usd]) table.append(["eth", 0, eth_usd]) print(tabulate(table, headers=["asset", "to send", "$ price"])) snap = BalanceSnapshotter( [badgerToken, bBadger], [badger.devMultisig, badger.deployer, badger.rewardsEscrow], ) snap.snap(name="Before Transfers") # Transfer assets to multisig # rewardsEscrow.transfer(badgerToken, safe, badger_to_send) snap.snap(name="After Transfers") snap.diff_last_two() # Deposit bBadger badgerToken.approve(bBadger.address, badger_to_send) bBadgerBefore = bBadger.balanceOf(safe) tx = bBadger.deposit(badger_to_send) bBadgerAfter = bBadger.balanceOf(badger.devMultisig) print( "bBadger to transfer", bBadgerAfter - bBadgerBefore, val(bBadgerAfter - bBadgerBefore), ) # bBadger.transfer(badger.paymentsMultisig, bBadgerAfter - bBadgerBefore) print(tx.events) snap.snap(name="After Deposits") snap.diff_last_two() safe_tx = safe.multisend_from_receipts() safe.preview(safe_tx) data = safe.print_transaction(safe_tx) safe.post_transaction(safe_tx)
def main(): """ First, swap half of the USDC into DAI Deposit USDC portion in to Yearn USDC Vault V2 Deposit DAI portion in to Yearn DAI Vault V2 For the deposits, create small test transactions first """ badger = connect_badger() expectedMultisig = "0xB65cef03b9B89f99517643226d76e286ee999e77" assert badger.devMultisig == expectedMultisig safe = ApeSafe(badger.devMultisig.address) helper = ApeSafeHelper(badger, safe) # Fetch tokens for snap + interactions usdc = safe.contract("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48") dai = safe.contract("0x6B175474E89094C44Da98b954EedeAC495271d0F") yDai = safe.contract("0x19D3364A399d251E894aC732651be8B0E4e85001") yUsdc = safe.contract("0x5f18C75AbDAe578b483E5F43f12a39cF75b973a9") usdc_to_deposit = "1500000000000" usdc_to_swap = "1500000000000" ## 1.5 * 10^6 (Million) * 10^6 (Decimals) # TODO: Track the balances of the tokens representing your position here: AAVE USDC (aUSDC), Compound USDC (cUSDC), y3Crv Vault Position (y3Crv) snap = BalanceSnapshotter( [usdc, dai, yDai, yUsdc], [ badger.devMultisig, ], ) snap.snap() current_dai_balance = dai.balanceOf(badger.devMultisig.address) ## NOTE: Swap to DAI with Curve ## Coins[0] == DAI ## Coins[1] == UDC curve_pool = safe.contract("0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7") dai_out = curve_pool.get_dy(1, 0, usdc_to_swap) with_slippage = dai_out * 0.99 print("With slippage") print(with_slippage) usdc.approve(curve_pool.address, usdc_to_swap) curve_pool.exchange(1, 0, usdc_to_swap, with_slippage) post_swap_balance = dai.balanceOf(badger.devMultisig.address) dai_to_deposit = post_swap_balance - current_dai_balance print("dai_to_deposit") print(dai_to_deposit) snap.snap() snap.diff_last_two() ## NOTE: Deposit DAI to Yearn ## TODO: Get balance of DAI to determine how to deposit yDaiVault = helper.contract_from_abi( "0x19D3364A399d251E894aC732651be8B0E4e85001", "yDaiVault", interface.VaultAPI.abi, ) dai.approve(yDaiVault.address, dai_to_deposit) yDaiVault.deposit(dai_to_deposit) snap.snap() snap.diff_last_two() ## NOTE: Deposit USDC to Yearn yUsdcVault = helper.contract_from_abi( "0x5f18C75AbDAe578b483E5F43f12a39cF75b973a9", "yUsdcVault", iinterface.VaultAPI.abi, ) usdc.approve(yUsdcVault.address, usdc_to_deposit) yUsdcVault.deposit(usdc_deposit_amount) ## DONE snap.snap() snap.diff_last_two() ## Publish all Txs helper.publish()
def main(): badger = connect_badger("deploy-final.json") digg = badger.digg admin = badger.devProxyAdmin multisig = badger.devMultisig contracts = badger.contracts_upgradeable deployer = badger.deployer expectedMultisig = "0xB65cef03b9B89f99517643226d76e286ee999e77" assert multisig == expectedMultisig safe = ApeSafe(badger.devMultisig.address) abi = Sett.abi badgerToken = safe.contract(badger.token.address) diggToken = safe.contract(digg.token.address) bBadger = safe.contract_from_abi( badger.getSett("native.badger").address, "Sett", abi) bDigg = safe.contract_from_abi( badger.getSett("native.digg").address, "Sett", abi) rewardsEscrow = safe.contract(badger.rewardsEscrow.address) badger_usd = fetch_usd_price(badger.token.address) eth_usd = fetch_usd_price_eth() # USD Denominated # badger_to_send = Wei(str(total_usd / badger_usd) + " ether") # Badger denominated badger_to_send = Wei("5970.744318 ether") table = [] table.append(["badger", badger_to_send, badger_usd]) table.append(["eth", 0, eth_usd]) print(tabulate(table, headers=["asset", "to send", "$ price"])) snap = BalanceSnapshotter( [badgerToken, bBadger], [badger.devMultisig, badger.deployer, badger.rewardsEscrow]) snap.snap(name="Before Transfers") # Transfer assets to multisig rewardsEscrow.transfer(badgerToken, badger.devMultisig, badger_to_send) snap.snap(name="After Transfers") snap.diff_last_two() # Deposit bBadger badgerToken.approve(bBadger.address, badger_to_send) bBadgerBefore = bBadger.balanceOf(badger.devMultisig) tx = bBadger.deposit(badger_to_send) bBadgerAfter = bBadger.balanceOf(badger.devMultisig) print("bBadger to transfer", bBadgerAfter - bBadgerBefore, val(bBadgerAfter - bBadgerBefore)) # bBadger.transfer(badger.treasuryMultisig, bBadgerAfter - bBadgerBefore) print(tx.events) snap.snap(name="After Deposits") snap.diff_last_two() safe_tx = safe.multisend_from_receipts() safe.preview(safe_tx) data = safe.print_transaction(safe_tx) safe.post_transaction(safe_tx)
def test_main(): badger = connect_badger() digg = badger.digg dev = badger.deployer distribute_from_whales(dev, assets=["digg"]) digg.token.transfer(badger.devMultisig, digg.token.balanceOf(dev), {"from": dev}) multi = GnosisSafe(badger.devMultisig) safe = ApeSafe(badger.devMultisig.address) ops = ApeSafe(badger.opsMultisig.address) vault = safe.contract_from_abi( badger.getSett("experimental.digg").address, "StabilizeDiggSett", StabilizeDiggSett.abi, ) controller = ops.contract("0x9b4efA18c0c6b4822225b81D150f3518160f8609") logic = StabilizeDiggSett.deploy({"from": dev}) guestList = VipCappedGuestListBbtcUpgradeable.deploy({"from": dev}) guestList.initialize(vault) guestList.setGuestRoot( "0x71ef21975aea159ba123526bd3b7e28487fb70e424f3450274293eeeaefcab6f", {"from": dev}, ) guestList.setTotalDepositCap(MaxUint256, {"from": dev}) guestList.setUserDepositCap(MaxUint256, {"from": dev}) badger.testProxyAdmin.upgrade(vault, logic, {"from": dev}) stabilizeVault = "0xE05D2A6b97dce9B8e59ad074c2E4b6D51a24aAe3" diggTreasury = DiggTreasury.deploy({"from": dev}) strategy = StabilizeStrategyDiggV1.deploy({"from": dev}) strategy.initialize( badger.devMultisig, dev, controller, badger.keeper, badger.guardian, 0, [stabilizeVault, diggTreasury], [250, 0, 50, 250], {"from": dev}, ) diggTreasury.initialize(strategy, {"from": dev}) """ address _governance, address _strategist, address _controller, address _keeper, address _guardian, uint256 _lockedUntil, address[2] memory _vaultConfig, uint256[4] memory _feeConfig """ print("governance", controller.governance()) vault.unpause() vault.setController(controller) controller.approveStrategy(digg.token, strategy) controller.setStrategy(digg.token, strategy) print(controller.address) print(vault.address) print(controller.vaults(digg.token)) assert controller.vaults(digg.token) == vault assert controller.strategies(digg.token) == strategy assert vault.token() == strategy.want() diggToken = safe.contract(digg.token.address) diggToken.approve(vault, MaxUint256) a = digg.token.balanceOf(badger.devMultisig) assert vault.guestList() == AddressZero vault.setGuestList(guestList) assert vault.guestList() == guestList assert digg.token.balanceOf(badger.devMultisig) > 1000000 assert digg.token.allowance(badger.devMultisig, vault) == MaxUint256 vault.setKeeper(badger.keeper) assert vault.keeper() == badger.keeper vault.deposit(a // 2) tx = vault.earn() # vault.earn({"from": badger.keeper}) strategy.rebalance({"from": badger.keeper}) vault.withdrawAll()
def main(): """ AAVE Compoound y3Crv """ badger = connect_badger() expectedMultisig = "0xB65cef03b9B89f99517643226d76e286ee999e77" assert badger.devMultisig == expectedMultisig # AAVE aave = registry.aave_system() tokens = registry.token_system() compound = registry.compound_system() usdc = tokens.erc20_by_key("usdc") dfd = tokens.erc20_by_key("dfd") ausdc = tokens.erc20_by_key("ausdc") cusdc = compound.ctoken("usdc") safe = ApeSafe(badger.devMultisig.address) # TODO: Track the balances of the tokens representing your position here: AAVE USDC (aUSDC), Compound USDC (cUSDC), y3Crv Vault Position (y3Crv) # TODO: Figure out the addresses of these derived tokens # TODO: Track the balances of all the appropriate contracts where the USDC ends up snap = BalanceSnapshotter( [usdc, ausdc, cusdc, dfd, badger.token], [ badger.devMultisig, aave.lendingPool, cusdc, compound.comptroller, badger.badgerTree, ], ) usdc_per_position = Wei("3237154580000 wei") # szabo = 10^6 round_1 = Wei("1000000 wei") round_2 = usdc_per_position - round_1 print(round_1, round_2) lendingPool = safe.contract(aave.lendingPool.address) usdcToken = safe.contract(usdc.address) dfd = safe.contract(dfd.address) rewardsEscrow = safe.contract(badger.rewardsEscrow.address) comptroller = safe.contract(compound.comptroller.address) cusdc = safe.contract(cusdc.address) snap.snap() # Tree Tokens """ Deposit badger from rewardsEscrow, and DFD from self. About 200k tokens. 60k Badger 200k DFD (We have plenty of DIGG) """ # rewardsEscrow.transfer(badger.token, badger.badgerTree, Wei("50000 ether")) # dfd.transfer(badger.badgerTree, Wei("200000 ether")) # # AAVE Deposit Test # usdcToken.approve(aave.lendingPool, round_1) # lendingPool.deposit(usdc, round_1, badger.devMultisig, 0) # Compound Deposit Test """ comptroller.enterMarkets([usdc]) usdc.approve(cUSDC) cUSDC.mint(<usdc amount>) """ # comptroller.enterMarkets([usdc]) # usdcToken.approve(cusdc, round_1) # cusdc.redeem(round_1) # lendingPool.withdraw(usdc, round_1, badger.devMultisig) snap.snap() snap.diff_last_two() # AAVE Deposit Full usdcToken.approve(aave.lendingPool, round_2) lendingPool.deposit(usdc, round_2, badger.devMultisig, 0) # Compound Deposit Full usdcToken.approve(cusdc, round_2) cusdc.mint(round_2) snap.snap() snap.diff_last_two() helper = ApeSafeHelper(badger, safe) helper.publish() """