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()
Exemple #2
0
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)
Exemple #3
0
def main():
    """
    Add contracts manually to guest list. They will now be approved regardless of merkle root situation
    """
    badger = connect_badger()
    safe = ApeSafe(badger.testMultisig.address)
    helper = ApeSafeHelper(badger, safe)

    for strategy_key in strategies_to_approve:
        strategy_address = badger.getStrategy(strategy_key).address
        source = helper.contract_from_abi(
            badger.getStrategy(strategy_key).address,
            "StrategyConvexStakingOptimizer",
            StrategyConvexStakingOptimizer.abi,
        )

        for guest_list_key in guest_lists_by_id:
            guestList = helper.contract_from_abi(
                badger.getGuestList(guest_list_key).address,
                "VipCappedGuestListBbtcUpgradeable",
                VipCappedGuestListBbtcUpgradeable.abi,
            )
            console.print(
                f"Approve [green]{strategy_address}[/green] on Guest list [yellow]{guest_list_key} ({guestList.address})[/yellow]"
            )
            guestList.setGuests([strategy_address], [True])
            assert guestList.guests(strategy_address) == True

    helper.publish()
def main():
    # Connect badger system from file
    badger = connect_badger()

    # Sanity check file addresses
    expectedMultisig = "0xB65cef03b9B89f99517643226d76e286ee999e77"
    assert badger.devMultisig == expectedMultisig

    safe = ApeSafe(badger.devMultisig.address)
    helper = ApeSafeHelper(badger, safe)

    setts = [
        helper.getSett("native.renCrv"),
        helper.getSett("native.tbtcCrv"),
        helper.getSett("native.sbtcCrv"),
        helper.getSett("native.sushiWbtcEth"),
    ]

    for contract in contracts_to_approve:
        for sett in setts:
            console.print(
                f"Approving contract access for: \n {contract} on \n [green]{sett.address}"
            )
            sett.approveContractAccess(contract)
            assert sett.approved(contract) == True

    helper.publish()
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():
    badger = connect_badger()

    bDigg = badger.getSett("native.digg")

    # rug = accounts.at(web3.toChecksumAddress("0x533e3c0e6b48010873b947bddc4721b1bdff9648"), force=True)
    # print(bDigg.balanceOf(rug))
    # bDigg.transfer(badger.devMultisig, amount, {"from": rug})

    bDigg_to_deposit = amount
    print("bDigg_to_deposit", bDigg_to_deposit)
    round_1 = Wei("1 ether")
    round_2 = bDigg_to_deposit - round_1

    safe = ApeSafe(badger.devMultisig.address)
    bDigg = safe.contract_from_abi(
        "0x7e7E112A68d8D2E221E11047a72fFC1065c38e1a", "Sett", Sett.abi)
    dropt = safe.contract_from_abi(
        web3.toChecksumAddress("0x02660b54750efab874fb43b4b613c135c7815eef"),
        "SyntheticToken",
        SyntheticToken.abi,
    )
    kpiOptions = safe.contract_from_abi(
        web3.toChecksumAddress("0xbc044745f137d4693c2aa823c760f855254fad42"),
        "ExpiringMultiParty",
        ExpiringMultiParty.abi,
    )

    snap = BalanceSnapshotter([bDigg, dropt],
                              [badger.devMultisig, kpiOptions, dropt])

    snap.snap()

    bDigg.approve(kpiOptions, bDigg_to_deposit)
    kpiOptions.create([round_1], [int(round_1 * 1000)])
    kpiOptions.create([round_2], [int(round_2 * 1000)])
    chain.mine()

    snap.snap()

    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(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()
Exemple #9
0
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)
Exemple #10
0
def main():
    """
    Promote an experimental vault to official status
    """
    badger = connect_badger(load_deployer=True)

    if rpc.is_active():
        dev_multi = ApeSafe(badger.testMultisig.address)
        helper = ApeSafeHelper(badger, dev_multi)
        assert True
    else:
        from helpers.gas_utils import gas_strategies

        gas_strategies.set_default(gas_strategies.exponentialScalingFast)
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!")
Exemple #12
0
def main():
    badger = connect_badger(load_deployer=True)

    safe = ApeSafe(badger.opsMultisig.address)
    helper = ApeSafeHelper(badger, safe)
    logger = helper.contract_from_abi(badger.rewardsLogger.address,
                                      "RewardsLogger", RewardsLogger.abi)

    schedules = []

    # Concat schedules for all vaults
    for key in vaults_to_run:
        vault = badger.getSett(key)

        start = 1625158800
        duration = days(7)
        end = start + duration

        badger_amount = Wei("360 ether")

        schedules.append(
            LoggerUnlockSchedule((
                vault,
                badger.token.address,
                badger_amount,
                start,
                end,
                duration,
            )), )

    # Add all schedules to logger
    for i in range(0, len(schedules)):
        schedule = schedules[i]
        logger.setUnlockSchedule(
            schedule.beneficiary,
            schedule.token,
            schedule.amount,
            schedule.start,
            schedule.end,
            schedule.duration,
        )

    # Print
    for key in vaults_to_run:
        vault = badger.getSett(key)
        badger.print_logger_unlock_schedules(vault, name=vault.name())

    helper.publish()
Exemple #13
0
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 main():
    badger = connect_badger()
    safe = ApeSafe(badger.testMultisig.address)
    helper = ApeSafeHelper(badger, safe)

    for source_key in to_approve:
        source = badger.getStrategy(source_key).address
        # source = helper.contract_from_abi(badger.getStrategy(source_key), "StrategyConvexStakingOptimizer", StrategyConvexStakingOptimizer.abi)
        for dest_key in destination_setts:
            destination = helper.contract_from_abi(
                badger.getSett(dest_key).address, "SettV3", SettV3.abi)
            console.print(
                f"Approve [green]{source}[/green] on Sett [yellow]{dest_key} ({destination.address})"
            )
            destination.approveContractAccess(source)

    helper.publish()
Exemple #15
0
def main():
    badger = connect_badger(load_deployer=True)

    safe = ApeSafe(badger.opsMultisig.address)
    helper = ApeSafeHelper(badger, safe)
    logger = helper.contract_from_abi(badger.rewardsLogger.address,
                                      "RewardsLogger", RewardsLogger.abi)

    schedules = build_weekly_schedules(badger, start, duration)
    console.print(schedules)
    set_schedules(logger, schedules)

    for key in badger.getAllSettIds():
        sett = badger.getSett(key)
        badger.print_logger_unlock_schedules(sett.address, name=sett.name())

    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
Exemple #17
0
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()
    
    safe = ApeSafe(badger.opsMultisig.address)

    nft = safe.contract_from_abi(
        badger_nft_address, "IBadgerERC1155", interface.IBadgerERC1155.abi
    )
    assert nft.totalSupply(nft_id) == 210

    print(len(third_set))

    for recipient in third_set:
        nft.safeTransferFrom(badger.opsMultisig.address, recipient, nft_id, 1, "0x")
        console.print(recipient, nft.balanceOf(recipient, nft_id))
        assert nft.balanceOf(recipient, nft_id) == 1

    print("Remaining After Transfer", nft.balanceOf(badger.opsMultisig, nft_id))

    safe_tx = safe.multisend_from_receipts()
    safe.preview(safe_tx)
    data = safe.print_transaction(safe_tx)

    safe.post_transaction(safe_tx)
Exemple #19
0
def main():
    # Connect badger system from file
    badger = connect_badger()

    # Sanity check file addresses
    expectedMultisig = "0xB65cef03b9B89f99517643226d76e286ee999e77"
    assert badger.devMultisig == expectedMultisig

    safe = ApeSafe(badger.devMultisig.address)
    helper = ApeSafeHelper(badger, safe)

    sett = helper.getSett("native.renCrv")

    for contract in contracts_to_approve:
        sett.approveContractAccess(contract)

    assert sett.approved(contract) == True

    helper.publish()
def main():
    """
    Add contracts manually to guest list. They will now be approved regardless of merkle root situation
    """
    badger = connect_badger()
    safe = ApeSafe(badger.testMultisig.address)
    helper = ApeSafeHelper(badger, safe)

    for sett_key in setts:
        sett = helper.contract_from_abi(
            badger.getSett(sett_key).address, "SettV4", SettV4.abi)
        guestList = badger.getGuestList(sett_key)

        old_state = {
            "guestList": sett.guestList(),
            "guestRoot": guestList.guestRoot(),
            "totalCap": guestList.totalDepositCap(),
            "userCap": guestList.userDepositCap(),
            "wrapper": guestList.wrapper(),
        }

        sett.setGuestList(guestList)

        print("proxyAdmin", badger.getProxyAdmin(guestList))

        new_state = {
            "guestList": sett.guestList(),
            "guestRoot": guestList.guestRoot(),
            "totalCap": guestList.totalDepositCap(),
            "userCap": guestList.userDepositCap(),
            "wrapper": guestList.wrapper(),
        }

        assert new_state["guestList"] != old_state["guestList"]
        assert new_state["guestList"] == guestList

        assert new_state["guestRoot"] == old_state["guestRoot"]
        assert new_state["totalCap"] == old_state["totalCap"]
        assert new_state["userCap"] == old_state["userCap"]
        assert new_state["wrapper"] == old_state["wrapper"]

    helper.publish()
Exemple #21
0
def main():
    """
    Add contracts manually to guest list. They will now be approved regardless of merkle root situation
    """
    badger = connect_badger()
    safe = ApeSafe(badger.testMultisig.address)
    helper = ApeSafeHelper(badger, safe)

    for guest_list_key in guest_lists_by_id:
        guestList = helper.contract_from_abi(
            badger.getGuestList(guest_list_key).address,
            "VipCappedGuestListBbtcUpgradeable",
            VipCappedGuestListBbtcUpgradeable.abi,
        )
        console.print(
            f"Set guest root to [green]{root}[/green] on Guest list [yellow]{guest_list_key} ({guestList.address})[/yellow]"
        )
        guestList.setGuestRoot(root)
        assert guestList.guestRoot() == root

    helper.publish()
Exemple #22
0
def main():
    badger = connect_badger()

    if rpc.is_active():
        dev_multi = ApeSafe(badger.testMultisig.address)
        helper = ApeSafeHelper(badger, dev_multi)
    else:
        from helpers.gas_utils import gas_strategies

        gas_strategies.set_default(gas_strategies.exponentialScalingFast)

    # Deploy logic
    logic = GatedMiniMeController.deploy({"from": badger.deployer})
    logic.initialize(badger.token)

    # Deploy proxy

    # Create Aragon Vote

    # Execute Aragon Vote
    # badger.voteWithSystemContracts(voteId)

    helper.publish()
Exemple #23
0
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():
    """
    Transfer badger to recipient, ensuring they are approved as recipient first
    Use test tx, full tx model
    Can convert from dollar value

    Assumes each token is a safeContract
    """

    badger = connect_badger()
    digg = badger.digg
    multisig = badger.devMultisig

    safe = ApeSafe(multisig.address)
    helper = ApeSafeHelper(badger, safe)

    rewardsEscrow = helper.contract_from_abi(badger.rewardsEscrow.address,
                                             "RewardsEscrow",
                                             RewardsEscrow.abi)
    vesting = helper.contract_from_abi(badger.digg.daoDiggTimelock.address,
                                       "SimpleTimelock", SimpleTimelock.abi)
    # dfd = helper.contract_from_abi(registry.token_address_by_key("dfd"), "IERC20", interface.IERC20.abi)
    diggToken = helper.contract_from_abi(badger.digg.token.address, "IERC20",
                                         interface.IERC20.abi)

    transfers = [
        TransferOp(badger.paymentsMultisig, badger.token, Wei("51222 ether")),
        # TransferOp(badger.badgerTree, badger.token, Wei("20000 ether")),
        # TransferOp(badger.badgerTree, dfd, Wei("200000 ether")),
        # TransferOp(badger.badgerRewardsManager, badger.token, Wei("10000 ether")),
        # TransferOp(badger.badgerRewardsManager, diggToken, Wei("2 gwei")),
    ]

    snap = BalanceSnapshotter(
        [badger.token, badger.digg.token],
        [
            badger.badgerTree,
            badger.badgerRewardsManager,
            badger.devMultisig,
            badger.rewardsEscrow,
            badger.paymentsMultisig,
        ],
    )
    snap.snap()

    rewards_escrow_tokens = [badger.token]

    for transfer in transfers:
        recipient = transfer.recipient
        token = transfer.token
        amount = transfer.amount

        console.print("Transfer", recipient, token, amount)

        # Transfer from rewards escrow
        if token.address in rewards_escrow_tokens:
            if not rewardsEscrow.isApproved(recipient):
                rewardsEscrow.approveRecipient(recipient)
            rewardsEscrow.transfer(token, recipient, amount)

        # Default: Transfer from treasury
        else:
            # Unlock from vesting
            if token.address == badger.digg.token.address:
                vesting.release(amount)
            token.transfer(recipient, amount)

    snap.snap()
    snap.diff_last_two()

    helper.publish()
Exemple #25
0
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():
    """
    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()
    """
Exemple #27
0
def main():
    badger = connect_badger()
    multisig = badger.paymentsMultisig

    safe = ApeSafe(multisig.address)
    helper = ApeSafeHelper(badger, safe)

    payments = load_ltcc_recipients("data/ltcc_recipients.csv")
    payments.calc_totals()
    payments.print_recipients()

    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)

    snap = BalanceSnapshotter(
        [badgerToken, bBadger, usdcToken],
        [multisig, badger.deployer, badger.rewardsEscrow],
    )
    snap.snap()
    # TODO: Do this in bBadger going forward - this is the way.
    # Approve treasury multi to stake
    # Deposit badger -> bBadger
    # console.print(f"Converting total of {val(payments.totals['badger'])} badger into bBadger")

    # badgerToken.approve(bBadger, payments.totals['badger'])
    # bBadger.deposit(payments.totals['badger'])

    # snap.snap()
    # snap.diff_last_two()

    # helper.publish()
    # return True

    for recipient in payments.recipients:
        snap.add_account(recipient.address)

    snap.snap(name="Before Transfers")

    for recipient in payments.recipients:
        bBadger_amount = badger_to_bBadger(badger,
                                           recipient.get_amount("badger"))
        console.print(recipient.address, recipient.get_amount("badger"),
                      bBadger_amount)
        diff = bBadger_amount - bBadger.balanceOf(multisig)

        console.print(bBadger.balanceOf(multisig), diff)

        if bBadger.balanceOf(multisig) < bBadger_amount:
            assert diff < Wei("0.1 ether")
            bBadger_amount = bBadger.balanceOf(multisig)

        tx = usdcToken.transfer(recipient.address,
                                recipient.get_amount("usdc"))
        tx = bBadger.transfer(recipient.address, bBadger_amount)

    snap.snap(name="After Transfers")
    snap.diff_last_two()

    helper.publish()
def main():
    badger = connect_badger()
    multisig = badger.paymentsMultisig

    safe = ApeSafe(multisig.address)

    payments = load_ltcc_recipients("data/ltcc_recipients.csv")
    payments.calc_totals()
    payments.print_recipients()

    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
    )

    # TODO: Do this in bBadger going forward - this is the way.
    # Approve treasury multi to stake
    # Deposit badger -> bBadger

    snap = BalanceSnapshotter(
        [badgerToken, bBadger, usdcToken],
        [multisig, badger.deployer, badger.rewardsEscrow],
    )

    for recipient in payments.recipients:
        snap.add_account(recipient.address)

    snap.snap(name="Before bBadger Deposit")

    assert bBadger.approved(multisig)
    badger_total = payments.totals["badger"]
    assert badgerToken.balanceOf(multisig.address) >= badger_total
    bBadger_total = badger_to_bBadger(badger, badger_total)
    badgerToken.approve(bBadger, badger_total)

    assert badgerToken.allowance(multisig.address, bBadger.address) >= badger_total
    bBadger.deposit(badger_total)

    snap.snap(name="After bBadger Deposit")
    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.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)
Exemple #30
0
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()