def get_lp():
    pd_provider = Contract("0x057835Ad21a177dbdd3090bB1CAE03EaCF78Fc6d")
    a_provider = Contract(pd_provider.ADDRESSES_PROVIDER())
    return Contract(a_provider.getLendingPool())
def test_clone(
    vault,
    strategy,
    strategist,
    rewards,
    keeper,
    gov,
    token,
    token_whale,
    borrow_token,
    borrow_whale,
    yvault,
    cloner,
):
    pd_provider = Contract("0x057835Ad21a177dbdd3090bB1CAE03EaCF78Fc6d")
    a_provider = Contract(pd_provider.ADDRESSES_PROVIDER())
    lp = Contract(a_provider.getLendingPool())
    vault_snx = Contract("0xF29AE508698bDeF169B89834F76704C3B205aedf")
    snx = Contract(vault_snx.token())
    snx_whale = "0xA1d7b2d891e3A1f9ef4bBC5be20630C2FEB1c470"
    clone_tx = cloner.cloneAaveLenderBorrower(
        vault,
        strategist,
        rewards,
        keeper,
        vault_snx,
        True,
        False,
        "StrategyAaveLender" + token.symbol() + "BorrowerSNX",
    )
    cloned_strategy = Contract.from_abi("Strategy",
                                        clone_tx.events["Cloned"]["clone"],
                                        strategy.abi)

    cloned_strategy.setStrategyParams(
        strategy.targetLTVMultiplier(),
        strategy.warningLTVMultiplier(),
        strategy.acceptableCostsRay(),
        0,
        strategy.maxTotalBorrowIT(),
        strategy.isWantIncentivised(),
        False,  # snx is not incentivised
        strategy.leaveDebtBehind(),
        strategy.maxLoss(),
        strategy.maxGasPriceToTend(),
        {"from": strategy.strategist()},
    )

    uniswap = Contract("0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D")
    cloned_strategy.switchDex(True, {"from": gov})
    assert cloned_strategy.router() == uniswap

    # should fail due to already initialized
    with reverts():
        strategy.initialize(vault, vault_snx, "NameRevert", {"from": gov})

    vault.updateStrategyDebtRatio(strategy, 0, {"from": gov})
    vault.addStrategy(cloned_strategy, 10_000, 0, 2**256 - 1, 0, {"from": gov})

    token.approve(vault, 2**256 - 1, {"from": token_whale})
    vault.deposit(10 * (10**token.decimals()), {"from": token_whale})
    strategy = cloned_strategy
    print_debug(vault_snx, strategy, lp)
    tx = strategy.harvest({"from": gov})
    assert vault_snx.balanceOf(strategy) > 0
    print_debug(vault_snx, strategy, lp)

    # Sleep for 2 days
    chain.sleep(60 * 60 * 24 * 2)
    chain.mine(1)

    # Send some profit to yvETH
    snx.transfer(vault_snx, 1_000 * (10**snx.decimals()), {"from": snx_whale})

    # TODO: check profits before and after
    strategy.harvest({"from": gov})
    print_debug(vault_snx, strategy, lp)

    # We should have profit after getting some profit from yvETH
    assert vault.strategies(strategy).dict()["totalGain"] > 0
    assert vault.strategies(strategy).dict()["totalLoss"] == 0

    # Enough sleep for profit to be free
    chain.sleep(60 * 60 * 10)
    chain.mine(1)
    print_debug(vault_snx, strategy, lp)

    # why do we have losses? because of interests
    with reverts():
        vault.withdraw()

    # so we send profits
    snx.transfer(vault_snx, Wei("30_000 ether"), {"from": snx_whale})
    vault.withdraw({"from": token_whale})