コード例 #1
0
def rapid_harvest(badger):
    """
    Atomically transfer and deposit tokens from rewards manager to associated strategies
    Requires that LP positons are swapped
    """

    # TODO: Output message when failure
    # TODO: Use test mode if RPC active, no otherwise

    rewards = get_active_rewards_schedule(badger)
    digg = badger.digg
    manager = badger.badgerRewardsManager

    if rpc.is_active():
        """
        Test: Load up sending accounts with ETH and whale tokens
        """
        accounts[0].transfer(badger.deployer, Wei("5 ether"))
        accounts[0].transfer(badger.external_harvester, Wei("5 ether"))
        accounts[0].transfer(badger.guardian, Wei("5 ether"))

    # TODO: Daily amount = calculate from the LP token scale

    # # ===== native.uniBadgerWbtc =====
    key = "native.uniBadgerWbtc"
    want = badger.getStrategyWant(key)
    transfer_for_strategy(badger, key, want.balanceOf(manager))

    # # # ===== native.sushiBadgerWbtc =====
    key = "native.sushiBadgerWbtc"
    want = badger.getStrategyWant(key)
    transfer_for_strategy(badger, key, want.balanceOf(manager))

    # # # ===== native.uniDiggWbtc =====
    key = "native.uniDiggWbtc"
    want = badger.getStrategyWant(key)
    transfer_for_strategy(badger, key, want.balanceOf(manager))

    # # # ===== native.sushiDiggWbtc =====
    key = "native.sushiDiggWbtc"
    want = badger.getStrategyWant(key)
    transfer_for_strategy(badger, key, want.balanceOf(manager))

    # ===== native.badger =====
    key = "native.badger"
    # TODO: Specify actual amounts here
    transfer_for_strategy(
        badger, key,
        rewards.getDistributions(key).getToStakingRewardsDaily("badger"))

    # ===== native.digg =====
    key = "native.digg"
    diggBaseRewards = shares_to_fragments(
        rewards.getDistributions(key).getToStakingRewardsDaily("digg"))
    transfer_for_strategy(
        badger,
        key,
        diggBaseRewards,
        decimals=9,
    )
コード例 #2
0
def main():
    badger = connect_badger("deploy-final.json")
    admin = badger.devProxyAdmin
    multisig = badger.devMultisig
    contracts = badger.contracts_upgradeable
    deployer = badger.deployer

    expectedMultisig = "0xB65cef03b9B89f99517643226d76e286ee999e77"
    assert multisig == expectedMultisig

    rest = get_active_rewards_schedule(badger)

    rest.printState("Week ?? - who knows anymore")

    recipient = accounts.at(expectedMultisig, force=True)

    # rest.transfer(badger.token, 33038371371007690000000, recipient)
    # rest.transfer(badger.digg.token, Wei("3 gwei"), badger.treasuryMultisig)

    rest.testTransactions()
    console.print(rest.totals)
    console.print(shares_to_fragments(rest.totals["digg"]))
コード例 #3
0
def main():
    badger = connect_badger("deploy-final.json")

    test_user = accounts.at(decouple.config("TEST_ACCOUNT"), force=True)

    distribute_test_ether(test_user, Wei("20 ether"))
    distribute_from_whales(test_user, assets=["bBadger", "badger", "usdc"])

    rest = get_active_rewards_schedule(badger)
    usdc = interface.IERC20(registry.tokens.usdc)

    usdc_per_badger = 40.37 * 0.75
    usdc_total = 13386240

    multi = GnosisSafe(badger.devMultisig)

    badger_total_scaled = usdc_total / usdc_per_badger

    badger_total = Wei(str(badger_total_scaled) + " ether")

    bBadger = badger.getSett("native.badger")

    ppfs = bBadger.getPricePerFullShare()

    bBadger_total = int(badger_total / ppfs * 10**18)

    badger_total = Wei(str(badger_total_scaled) + " ether")

    console.print({
        "TRADE": "BASED",
        "usdc_per_badger": usdc_per_badger,
        "usdc_total": usdc_total,
        "badger_total_scaled": badger_total_scaled,
        "badger_total": badger_total,
        "ppfs": ppfs,
        "bBadger_total": str(bBadger_total),
    })

    params = {
        "beneficiary": "0x3159b46a7829a0dbfa856888af768fe7146e7418",
        "duration": days(182),
        "usdcAmount": usdc_total * 10**6,
        "bBadgerAmount": bBadger_total,
        # "usdcAmount": 0,
        # "bBadgerAmount": 0,
    }

    console.print(params)

    # # Oxb1 Test
    beneficiary = accounts.at(params["beneficiary"], force=True)

    escrow = OtcEscrow.at("0x7163fB2fA38Ea3BBc1F8525F3d8D0417C0c9d903")

    # bBadger.transfer(badger.devMultisig, Wei("100000 ether"), {"from": test_user})

    pre = get_token_balances(
        [usdc, bBadger], [test_user, escrow, badger.devMultisig, beneficiary])
    pre.print()

    # assert usdc.balanceOf(params["beneficiary"]) >= params["usdcAmount"]

    # multi.execute(MultisigTxMetadata(description="Transfer to 0xb1"), {
    #     "to": bBadger.address,
    #     "data": bBadger.transfer.encode_input(escrow, bBadger_total + Wei("1000 ether"))
    # })

    # assert usdc.allowance(beneficiary, escrow) >= params["usdcAmount"]

    # usdc.approve(escrow, params["usdcAmount"], {"from": beneficiary})
    # tx = escrow.swap({"from": beneficiary})

    tx = multi.execute(MultisigTxMetadata(description="Swap"), {
        "to": escrow.address,
        "data": escrow.swap.encode_input()
    },
                       print_output=False)

    chain.mine()

    print(tx.call_trace())

    vesting = interface.ITokenTimelock(
        tx.events["VestingDeployed"][0]["vesting"])

    console.print({
        "token": vesting.token(),
        "beneficiary": vesting.beneficiary(),
        "releaseTime": to_utc_date(vesting.releaseTime()),
    })

    post = get_token_balances(
        [usdc, bBadger], [test_user, escrow, badger.devMultisig, beneficiary])

    diff_token_balances(pre, post)
    try:
        vesting.release({"from": test_user})
    except:
        print("early vest failed!")

    chain.sleep(days(182))
    chain.mine()
    # End

    vesting.release({"from": test_user})

    post = get_token_balances(
        [usdc, bBadger], [test_user, escrow, badger.devMultisig, beneficiary])

    diff_token_balances(pre, post)

    return

    escrow = OtcEscrow.deploy(
        params["beneficiary"],
        params["duration"],
        params["usdcAmount"],
        params["bBadgerAmount"],
        {"from": badger.deployer},
    )

    beneficiary = accounts.at(params["beneficiary"], force=True)
    usdc.transfer(beneficiary, params["usdcAmount"], {"from": test_user})
    usdc.transfer(beneficiary, 1500000000000, {"from": test_user})

    badger.token.transfer(badger.devMultisig, badger_total,
                          {"from": test_user})

    multi.execute(
        MultisigTxMetadata(description="Whitelist Multi"),
        {
            "to": bBadger.address,
            "data": bBadger.approveContractAccess.encode_input(
                badger.devMultisig),
        },
    )

    assert badger.token.balanceOf(badger.devMultisig) > Wei("100 ether")

    multi.execute(
        MultisigTxMetadata(description="Approve bBadger Contract"),
        {
            "to": badger.token.address,
            "data": badger.token.approve.encode_input(bBadger, badger_total),
        },
    )

    multi.execute(
        MultisigTxMetadata(description="Deposit"),
        {
            "to": bBadger.address,
            "data": bBadger.deposit.encode_input(badger_total)
        },
    )

    console.print(
        "bBadger.balanceOf(badger.devMultisig)",
        bBadger.balanceOf(badger.devMultisig), params["bBadgerAmount"],
        params["bBadgerAmount"] - bBadger.balanceOf(badger.devMultisig))
    assert bBadger.balanceOf(badger.devMultisig) >= params["bBadgerAmount"]

    chain.mine()
    chain.sleep(14)
    chain.mine()

    multi.execute(
        MultisigTxMetadata(description="Transfer"),
        {
            "to": bBadger.address,
            "data": bBadger.transfer.encode_input(escrow,
                                                  params["bBadgerAmount"]),
        },
    )

    assert bBadger.balanceOf(escrow) == params["bBadgerAmount"]

    multi.execute(
        MultisigTxMetadata(description="Revoke"),
        {
            "to": escrow.address,
            "data": escrow.revoke.encode_input()
        },
    )

    assert bBadger.balanceOf(escrow) == 0
    assert bBadger.balanceOf(badger.devMultisig) >= params["bBadgerAmount"]

    print(bBadger.balanceOf(badger.devMultisig))

    bBadger.transfer(escrow, params["bBadgerAmount"], {"from": test_user})

    pre = get_token_balances(
        [usdc, bBadger], [test_user, escrow, badger.devMultisig, beneficiary])
    console.print(pre)

    assert usdc.balanceOf(beneficiary) >= params["usdcAmount"]
    assert bBadger.balanceOf(escrow) == params["bBadgerAmount"]

    usdc.approve(escrow, params["usdcAmount"], {"from": beneficiary})
    tx = escrow.swap({"from": beneficiary})

    post = get_token_balances(
        [usdc, bBadger], [test_user, escrow, badger.devMultisig, beneficiary])

    console.print(tx.events)
    post.print()
    diff_token_balances(pre, post)

    vesting = interface.ITokenTimelock(
        tx.events["VestingDeployed"][0]["vesting"])

    console.print({
        "token": vesting.token(),
        "beneficiary": vesting.beneficiary(),
        "releaseTime": to_utc_date(vesting.releaseTime()),
    })

    chain.sleep(days(365))
    chain.mine()

    vesting.release({"from": test_user})
コード例 #4
0
def main():
    """
    Swap daily allowance for LP tokens & run injection harvest
    """

    badger = connect_badger(load_external_harvester=True)
    rewards = get_active_rewards_schedule(badger)

    if rpc.is_active():
        """
        Test: Load up sending accounts with ETH and whale tokens
        """
        accounts[0].transfer(badger.deployer, Wei("5 ether"))
        accounts[0].transfer(badger.external_harvester, Wei("5 ether"))
        accounts[0].transfer(badger.guardian, Wei("5 ether"))

    # swap one day of tokens

    manager = badger.badgerRewardsManager

    # # ===== native.uniBadgerWbtc =====
    key = "native.uniBadgerWbtc"
    swap_for_strategy(
        badger,
        key,
        rewards.getDistributions(key).getToStakingRewardsDaily("badger") // 2,
    )
    lp_for_strategy(badger, key)

    # ===== native.sushiBadgerWbtc =====
    key = "native.sushiBadgerWbtc"
    swap_for_strategy(
        badger,
        key,
        rewards.getDistributions(key).getToStakingRewardsDaily("badger") // 2,
    )
    lp_for_strategy(badger, key)

    # # ===== native.uniDiggWbtc =====
    key = "native.uniDiggWbtc"
    swap_for_strategy(
        badger,
        key,
        shares_to_fragments(
            rewards.getDistributions(key).getToStakingRewardsDaily("digg") //
            2),
    )
    lp_for_strategy(badger, key)

    # # ===== native.sushiDiggWbtc =====
    key = "native.sushiDiggWbtc"
    swap_for_strategy(
        badger,
        key,
        shares_to_fragments(
            rewards.getDistributions(key).getToStakingRewardsDaily("digg") //
            2),
    )
    lp_for_strategy(badger, key)

    rapid_harvest(badger)
コード例 #5
0
def main():
    badger = connect_badger(badger_config.prod_json)
    rewards = get_active_rewards_schedule(badger)

    b1 = rewards.getDistributions(
        "native.uniBadgerWbtc").getToStakingRewardsDaily("badger") * 5
    b2 = rewards.getDistributions(
        "native.sushiBadgerWbtc").getToStakingRewardsDaily("badger") * 5
    b3 = rewards.getDistributions("native.badger").getToStakingRewardsDaily(
        "badger") * 5

    total_badger = b1 + b2 + b3

    d1 = shares_to_fragments(
        rewards.getDistributions(
            "native.uniDiggWbtc").getToStakingRewardsDaily("digg")) * 5
    d2 = shares_to_fragments(
        rewards.getDistributions(
            "native.sushiDiggWbtc").getToStakingRewardsDaily("digg")) * 5
    d3 = shares_to_fragments(
        rewards.getDistributions("native.digg").getToStakingRewardsDaily(
            "digg")) * 6

    total_digg = d1 + d2 + d3

    table = []
    table.append(["native.uniBadgerWbtc", val(b1)])
    table.append(["native.sushiBadgerWbtc", val(b2)])
    table.append(["native.badger", val(b3)])
    table.append(["total badger", val(total_badger)])
    print(tabulate(table, headers=["metric", "value"]))

    table = []
    table.append(["native.uniDiggWbtc", val(d1, decimals=9)])
    table.append(["native.sushiDiggWbtc", val(d2, decimals=9)])
    table.append(["native.digg", val(d3, decimals=9)])
    table.append(["total digg", val(total_digg, decimals=9)])
    print(tabulate(table, headers=["metric", "value"]))

    rewards.printState("Geyser Emissions")

    # Generate Sufficient
    multi = GnosisSafe(badger.devMultisig)

    print(badger.badgerRewardsManager)

    multi.execute(
        MultisigTxMetadata(description="Transfer Remaining Weekly Badger"), {
            "to":
            badger.rewardsEscrow.address,
            "data":
            badger.rewardsEscrow.transfer.encode_input(
                badger.token, badger.badgerRewardsManager, total_badger)
        })

    assert badger.token.balanceOf(badger.badgerRewardsManager) >= total_badger

    multi.execute(
        MultisigTxMetadata(description="Transfer Remaining Weekly Badger"), {
            "to":
            badger.rewardsEscrow.address,
            "data":
            badger.rewardsEscrow.transfer.encode_input(
                badger.digg.token, badger.badgerRewardsManager, total_digg)
        })

    assert badger.digg.token.balanceOf(
        badger.badgerRewardsManager) >= total_digg