コード例 #1
0
def test_live_status2(web3, chain, live_vault, live_strategy,  comp,dai, samdev):

  stateOfStrat(live_strategy, dai, comp)
  stateOfVault(live_vault, live_strategy)

  genericStateOfStrat(live_strategy, dai, live_vault)
  genericStateOfVault(live_vault, dai)
コード例 #2
0
def test_add_strat(live_vault_dai3, Contract,usdc, web3, accounts, chain, cdai, comp, dai, live_strategy_usdc3,live_vault_usdc3, live_strategy_dai3,live_gov, currency, whale,samdev):
    strategist = samdev
    strategy = live_strategy_usdc3
    vault = live_vault_usdc3
    currency = usdc
    gov = live_gov

    stateOfStrat(strategy, currency, comp)
    genericStateOfVault(vault, currency)

    
    vault.addStrategy(
        strategy,
        2 ** 256 - 1,2 ** 256 - 1, 
        1000,  # 0.5% performance fee for Strategist
        {"from": gov}
    )

   #amount = Wei('50000 ether')
    #print(dai.balanceOf(whale)/1e18)
    #dai.approve(vault, amount, {'from': whale})
    #vault.deposit(amount, {'from': whale})  
    chain.mine(1)

    strategy.harvest({'from': strategist})

    stateOfStrat(strategy, currency, comp)
    genericStateOfVault(vault, currency)
    genericStateOfStrat(strategy,currency, vault )
コード例 #3
0
def migration_live(web3,  comp, YearnDaiCompStratV2,live_strategy, live_vault,  dai, samdev):
    #stateOfStrat(live_strategy, dai, comp)
   # stateOfVault(live_vault, live_strategy)
    old_strategy = YearnDaiCompStratV2.at('0x4C6e9d7E5d69429100Fcc8afB25Ea980065e2773')

    live_strategy = YearnDaiCompStratV2.at('0x5b62F24581Ea4bc6d6C5C101DD2Ae7233E422884')

    print(f'strategy YearnDaiCompStratV2: {live_strategy.address}')

    print(f'Vault: {live_vault.address}')
    print(f'Vault name: {live_vault.name()} and symbol: {live_vault.symbol()}')

    print(f'Strategy strategist: {live_strategy.strategist()}')

    stateOfStrat(old_strategy, dai, comp)
    stateOfVault(live_vault, old_strategy)

    stateOfStrat(live_strategy, dai, comp)
    stateOfVault(live_vault, live_strategy)

    print(f'Migrating')
    live_vault.migrateStrategy(old_strategy, live_strategy, {'from': samdev})

    stateOfStrat(old_strategy, dai, comp)
    stateOfVault(live_vault, old_strategy)

    stateOfStrat(live_strategy, dai, comp)
    stateOfVault(live_vault, live_strategy)

    print(f'Harvesting')
    live_strategy.harvest({'from': samdev})

    stateOfStrat(live_strategy, dai, comp)
    stateOfVault(live_vault, live_strategy)
コード例 #4
0
def test_profit_is_expected(web3, chain, comp, vault, enormousrunningstrategy,
                            whale, gov, dai, strategist):
    enormousrunningstrategy.setGasFactor(1, {"from": strategist})
    assert (enormousrunningstrategy.gasFactor() == 1)

    startingBalance = vault.totalAssets()

    stateOfStrat(enormousrunningstrategy, dai, comp)
    stateOfVault(vault, enormousrunningstrategy)

    for i in range(50):
        assert vault.creditAvailable(enormousrunningstrategy) == 0
        waitBlock = 25
        print(f'\n----wait {waitBlock} blocks----')
        chain.mine(waitBlock)

        harvest(enormousrunningstrategy, strategist, vault)
        stateOfStrat(enormousrunningstrategy, dai, comp)
        stateOfVault(vault, enormousrunningstrategy)

        profit = (vault.totalAssets() - startingBalance).to('ether')
        strState = vault.strategies(enormousrunningstrategy)
        totalReturns = strState[6]
        totaleth = totalReturns.to('ether')
        print(f'Real Profit: {profit:.5f}')
        difff = profit - totaleth
        print(f'Diff: {difff}')

        blocks_per_year = 2_300_000
        assert startingBalance != 0
        time = (i + 1) * waitBlock
        assert time != 0
        apr = (totalReturns / startingBalance) * (blocks_per_year / time)
        print(f'implied apr: {apr:.8%}')
    vault.withdraw(vault.balanceOf(whale), {'from': whale})
コード例 #5
0
def test_add_keeper(live_vault_dai2, Contract, web3, accounts, chain, cdai, comp, dai, live_strategy_dai2,currency, whale,samdev):
    strategist = samdev
    strategy = live_strategy_dai2
    vault = live_vault_dai2

    #stateOfStrat(strategy, dai, comp)
    #genericStateOfVault(vault, dai)

    keeper = Contract.from_explorer("0x13dAda6157Fee283723c0254F43FF1FdADe4EEd6")

    kp3r = Contract.from_explorer("0x1cEB5cB57C4D4E2b2433641b95Dd330A33185A44")

    #strategy.setKeeper(keeper, {'from': strategist})

    #carlos = accounts.at("0x73f2f3A4fF97B6A6d7afc03C449f0e9a0c0d90aB", force=True)

    #keeper.addStrategy(strategy, 1700000, 10, {'from': carlos})

    bot = accounts.at("0xfe56a0dbdad44Dd14E4d560632Cc842c8A13642b", force=True)

    assert keeper.harvestable(strategy) == False

    depositAmount =  Wei('3500 ether')
    deposit(depositAmount, whale, currency, vault)

    assert keeper.harvestable(strategy) == False

    depositAmount =  Wei('1000 ether')
    deposit(depositAmount, whale, currency, vault)
    assert keeper.harvestable(strategy) == True

    keeper.harvest(strategy, {'from': bot})
    balanceBefore = kp3r.balanceOf(bot)
    #print(tx.events) 
    chain.mine(4)
    #assert kp3r.balanceOf(bot) > balanceBefore
    #strategy.harvest({'from': strategist})

    assert keeper.harvestable(strategy) == False

    stateOfStrat(strategy, dai, comp)
    genericStateOfVault(vault, dai)

    #stateOfStrat(strategy, dai, comp)
    #stateOfVault(vault, strategy)
    #depositAmount =  Wei('1000 ether')
    
    #deposit(depositAmount, whale, currency, vault)

    #stateOfStrat(strategy, dai, comp)
    #genericStateOfVault(vault, dai)

    #strategy.harvest({'from': strategist})

    #stateOfStrat(strategy, dai, comp)
    #genericStateOfVault(vault, dai)
コード例 #6
0
def test_huge_withdrawal(web3, chain, comp, vault, enormousrunningstrategy,
                         whale, gov, dai, strategist):
    stateOfStrat(enormousrunningstrategy, dai, comp)
    stateOfVault(vault, enormousrunningstrategy)
    print("\nwhale withdraws")
    vault.withdraw({"from": whale})
    assert (enormousrunningstrategy.estimatedTotalAssets() <
            vault.strategies(enormousrunningstrategy)[5])
    stateOfStrat(enormousrunningstrategy, dai, comp)
    genericStateOfStrat(enormousrunningstrategy, dai, vault)
    stateOfVault(vault, enormousrunningstrategy)

    enormousrunningstrategy.harvest({"from": gov})
コード例 #7
0
def test_screenshot(live_vault, live_strategy, Contract, web3, accounts, chain,
                    cream, currency, samdev, whale):
    vault = live_vault
    strategy = live_strategy
    print(vault.apiVersion())

    currency.approve(vault, 2**256 - 1, {'from': whale})

    vault.deposit(5 * 1e18, {'from': whale})
    strategy.harvest({'from': samdev})

    stateOfStrat(strategy, currency, cream)
    stateOfVault(vault, strategy)
コード例 #8
0
def test_migration(live_vault_dai3, live_strategy_dai3, live_strategy_usdc3,
                   live_strategy_usdc4, live_vault_usdc3, live_strategy_dai4,
                   Contract, usdc, web3, live_gov, accounts, chain, cdai, comp,
                   dai, live_strategy_dai2, currency, whale, samdev):

    vault = live_vault_dai3
    live_strat = live_strategy_dai4
    old_strat = live_strategy_dai3
    stateOfStrat(old_strat, dai, comp)

    vault.migrateStrategy(old_strat, live_strat, {'from': live_gov})

    live_strat.harvest({'from': samdev})
    stateOfStrat(live_strat, dai, comp)

    print('usdc done')
    vault = live_vault_usdc3
    live_strat = live_strategy_usdc4
    old_strat = live_strategy_usdc3
    stateOfStrat(old_strat, usdc, comp)

    vault.migrateStrategy(old_strat, live_strat, {'from': live_gov})

    live_strat.harvest({'from': samdev})
    stateOfStrat(live_strat, usdc, comp)
コード例 #9
0
def test_screenshot(live_vault_dai2,live_vault_dai3,live_strategy_dai3, Contract, web3,live_gov, accounts, chain, cdai, comp, dai, live_strategy_dai2,currency, whale,samdev):
    strategist = samdev
    strategy = live_strategy_dai3

    vault = live_vault_dai3

    stateOfStrat(strategy, dai, comp)
    genericStateOfVault(vault, dai)

    strategy.harvest({'from': strategist})

    stateOfStrat(strategy, currency, comp)
    genericStateOfVault(vault, currency)
    genericStateOfStrat(strategy,currency, vault )
コード例 #10
0
def test_getting_too_close_to_liq(web3, chain, comp, vault,
                                  largerunningstrategy, whale, gov, dai):

    stateOfStrat(largerunningstrategy, dai, comp)
    stateOfVault(vault, largerunningstrategy)
    largerunningstrategy.setCollateralTarget(Wei('0.74999999999 ether'),
                                             {"from": gov})
    deposit(Wei('1000 ether'), whale, dai, vault)

    balanceBefore = vault.totalAssets()
    collat = 0

    while collat < largerunningstrategy.collateralTarget() / 1.001e18:

        largerunningstrategy.harvest({'from': gov})
        deposits, borrows = largerunningstrategy.getCurrentPosition()
        collat = borrows / deposits

        stateOfStrat(largerunningstrategy, dai, comp)
        stateOfVault(vault, largerunningstrategy)
        assertCollateralRatio(largerunningstrategy)

    print(largerunningstrategy.getblocksUntilLiquidation())
    assert largerunningstrategy.tendTrigger(1e18) == True
    largerunningstrategy.tend({'from': gov})
    assertCollateralRatio(largerunningstrategy)
    stateOfStrat(largerunningstrategy, dai, comp)
    stateOfVault(vault, largerunningstrategy)

    largerunningstrategy.setCollateralTarget(Wei('0.73 ether'), {"from": gov})
    assert largerunningstrategy.tendTrigger(1e18) == False
    largerunningstrategy.tend({'from': gov})
    assertCollateralRatio(largerunningstrategy)
    stateOfStrat(largerunningstrategy, dai, comp)
    stateOfVault(vault, largerunningstrategy)
コード例 #11
0
def test_snapshot_both(live_vault_dai_030, live_strategy_dai_030,
                       live_vault_usdc_030, live_strategy_usdc_030, Contract,
                       whale, web3, live_gov, accounts, chain, cdai, comp, dai,
                       usdc, currency, samdev):
    strategist = samdev
    strategy = live_strategy_dai_030
    vault = live_vault_dai_030

    print("\nDAI")
    stateOfStrat(live_strategy_dai_030, dai, comp)
    genericStateOfVault(live_vault_dai_030, dai)
    genericStateOfStrat(live_strategy_dai_030, dai, live_vault_dai_030)

    print("\nUSDC")
    stateOfStrat(live_strategy_usdc_030, usdc, comp)
    genericStateOfVault(live_vault_usdc_030, usdc)
    genericStateOfStrat(live_strategy_usdc_030, usdc, live_vault_usdc_030)
コード例 #12
0
def test_apr_dai(web3, chain, comp, vault, enormousrunningstrategy, whale, gov,
                 dai, strategist):
    enormousrunningstrategy.setProfitFactor(1, {"from": strategist})
    assert enormousrunningstrategy.profitFactor() == 1

    enormousrunningstrategy.setMinCompToSell(1, {"from": gov})
    enormousrunningstrategy.setMinWant(0, {"from": gov})
    assert enormousrunningstrategy.minCompToSell() == 1

    startingBalance = vault.totalAssets()

    stateOfStrat(enormousrunningstrategy, dai, comp)
    stateOfVault(vault, enormousrunningstrategy)

    for i in range(6):

        waitBlock = 25
        print(f"\n----wait {waitBlock} blocks----")
        chain.sleep(21600)
        wait(waitBlock, chain)
        ppsBefore = vault.pricePerShare()

        harvest(enormousrunningstrategy, strategist, vault)
        ppsAfter = vault.pricePerShare()

        # stateOfStrat(enormousrunningstrategy, dai, comp)
        # stateOfVault(vault, enormousrunningstrategy)

        profit = (vault.totalAssets() - startingBalance).to("ether")
        strState = vault.strategies(enormousrunningstrategy)
        totalReturns = strState[6]
        totaleth = totalReturns.to("ether")
        print(f"Real Profit: {profit:.5f}")
        difff = profit - totaleth
        print(f"Diff: {difff}")

        blocks_per_year = 2_300_000
        assert startingBalance != 0
        time = (i + 1) * waitBlock
        assert time != 0
        ppsProfit = (ppsAfter - ppsBefore) / 1e18 / waitBlock * blocks_per_year
        apr = (totalReturns / startingBalance) * (blocks_per_year / time)
        print(f"implied apr assets: {apr:.8%}")
        print(f"implied apr pps: {ppsProfit:.8%}")
    vault.withdraw(vault.balanceOf(whale), {"from": whale})
コード例 #13
0
def test_enourmous_exit(web3, chain, comp, vault, enormousrunningstrategy,
                        whale, gov, dai, strategist):
    stateOfStrat(enormousrunningstrategy, dai, comp)
    stateOfVault(vault, enormousrunningstrategy)

    enormousrunningstrategy.setEmergencyExit({"from": gov})
    assert enormousrunningstrategy.emergencyExit()

    #genericStateOfStrat(strategy, currency, vault)
    #genericStateOfVault(vault, currency)
    ## emergency shutdown

    enormousrunningstrategy.harvest({'from': gov})
    stateOfStrat(enormousrunningstrategy, dai, comp)
    genericStateOfStrat(enormousrunningstrategy, dai, vault)
    stateOfVault(vault, enormousrunningstrategy)
    strState = vault.strategies(enormousrunningstrategy)
    assert strState[7] > 0
コード例 #14
0
ファイル: test_withdraw_all.py プロジェクト: Macarse/yearnv2
def test_leverage_up_and_down(web3, chain, comp, vault, largerunningstrategy,
                              whale, gov, dai, strategist, isolation):

    stateOfStrat(largerunningstrategy, dai, comp)
    stateOfVault(vault, largerunningstrategy)

    deposit(dai.balanceOf(whale), whale, dai, vault)

    balanceBefore = vault.totalAssets()
    collat = 0

    while collat < largerunningstrategy.collateralTarget() / 1.001e18:
        # while collat < largerunningstrategy.collateralTarget() :

        largerunningstrategy.harvest({'from': gov})
        deposits, borrows = largerunningstrategy.getCurrentPosition()
        collat = borrows / deposits
        print(collat)

        stateOfStrat(largerunningstrategy, dai, comp)
        stateOfVault(vault, largerunningstrategy)
        assertCollateralRatio(largerunningstrategy)

    harvest(largerunningstrategy, gov, vault)
    stateOfStrat(largerunningstrategy, dai, comp)
    stateOfVault(vault, largerunningstrategy)

    largerunningstrategy.setCollateralTarget(Wei('0.1 ether'), {"from": gov})
    largerunningstrategy.tend({'from': gov})

    stateOfStrat(largerunningstrategy, dai, comp)
    stateOfVault(vault, largerunningstrategy)

    while collat > largerunningstrategy.collateralTarget() / 1e18:
        # while collat < largerunningstrategy.collateralTarget() :

        largerunningstrategy.tend({'from': gov})
        deposits, borrows = largerunningstrategy.getCurrentPosition()
        collat = borrows / deposits
        print(collat)

        stateOfStrat(largerunningstrategy, dai, comp)
        stateOfVault(vault, largerunningstrategy)
コード例 #15
0
def test_deposit_live_dai(live_vault_dai_030, live_strategy_dai_030, Contract,
                          whale, web3, live_gov, accounts, chain, cdai, comp,
                          dai, currency, samdev):
    strategist = samdev
    strategy = live_strategy_dai_030
    vault = live_vault_dai_030

    stateOfStrat(strategy, currency, comp)
    genericStateOfVault(vault, currency)
    genericStateOfStrat(strategy, currency, vault)

    amount = Wei('499000 ether')
    dai.approve(vault, amount, {'from': whale})
    vault.deposit(amount, {'from': whale})

    strategy.harvest({'from': strategist})
    stateOfStrat(strategy, currency, comp)
    genericStateOfVault(vault, currency)
    genericStateOfStrat(strategy, currency, vault)
コード例 #16
0
def test_screenshot2(live_vault_usdc3, live_strategy_usdc4, usdc, Contract,
                     web3, live_gov, accounts, chain, cdai, comp, dai,
                     live_strategy_dai2, currency, samdev):
    strategist = samdev
    strategy = live_strategy_usdc4

    vault = live_vault_usdc3

    #  vault.revokeStrategy(strategy,{'from': live_gov})

    #  stateOfStrat(strategy, dai, comp)
    #   genericStateOfVault(vault, dai)
    print(chain.height)

    strategy.harvest({'from': strategist})
    strategy.harvest({'from': strategist})

    stateOfStrat(strategy, usdc, comp)
    genericStateOfVault(vault, usdc)
    genericStateOfStrat(strategy, usdc, vault)
コード例 #17
0
def test_comp_dis(web3, chain, comp, vault, largerunningstrategy, dai, gov):

    stateOfStrat(largerunningstrategy, dai)
    stateOfVault(vault, largerunningstrategy)

    wait(100, chain)

    # Claim COMP and check balance in strategy -> for testing _claimComp() needs to be public
    print('\n----checking comp----')
    balanceBefore = comp.balanceOf(largerunningstrategy)
    
    comp_prediction = largerunningstrategy._predictCompAccrued()
    print(comp_prediction.to('ether'), 'comp accrued')
    largerunningstrategy._claimComp({'from': gov})
    comp_balance = comp.balanceOf(largerunningstrategy) -balanceBefore
    print(comp_balance.to('ether'), 'comp claimed')

    assert comp_balance< comp_prediction*1.1 and comp_balance> comp_prediction*0.9

    stateOfStrat(largerunningstrategy, dai)
    stateOfVault(vault, largerunningstrategy)
コード例 #18
0
ファイル: test_withdraw_all.py プロジェクト: Macarse/yearnv2
def test_withdraw_all(web3, chain, comp, vault, largerunningstrategy, whale,
                      gov, dai, strategist, isolation):

    balance_before = dai.balanceOf(strategist)
    stateOfStrat(largerunningstrategy, dai, comp)
    stateOfVault(vault, largerunningstrategy)

    amount = Wei('10000 ether')
    deposit(amount, strategist, dai, vault)
    harvest(largerunningstrategy, gov, vault)

    wait(50, chain)
    harvest(largerunningstrategy, gov, vault)
    stateOfStrat(largerunningstrategy, dai, comp)
    stateOfVault(vault, largerunningstrategy)

    withdraw(1, strategist, dai, vault)

    profitW = dai.balanceOf(strategist) - balance_before
    profit = profitW.to('ether')
    print(f'profit: {profit:.5f}')
コード例 #19
0
def test_collat_zero(web3, chain, cream, vault, enormousrunningstrategy, whale,
                     gov, currency, strategist):
    dai = currency

    stateOfStrat(enormousrunningstrategy, dai, cream)
    stateOfVault(vault, enormousrunningstrategy)

    enormousrunningstrategy.setCollateralTarget(0, {"from": gov})
    lastCollat = enormousrunningstrategy.storedCollateralisation()
    while enormousrunningstrategy.storedCollateralisation() > 0.05 * 1e18:
        enormousrunningstrategy.harvest({"from": gov})
        newCollat = enormousrunningstrategy.storedCollateralisation()
        assert lastCollat > newCollat
        lastCollat = newCollat
        stateOfStrat(enormousrunningstrategy, dai, cream)
        stateOfVault(vault, enormousrunningstrategy)

    enormousrunningstrategy.setEmergencyExit({"from": gov})
    enormousrunningstrategy.harvest({'from': gov})

    stateOfStrat(enormousrunningstrategy, dai, cream)
    genericStateOfStrat(enormousrunningstrategy, dai, vault)
    stateOfVault(vault, enormousrunningstrategy)
    strState = vault.strategies(enormousrunningstrategy)
    #losses == 0 with elegent big withdrawal
    assert strState[7] < 1e16
コード例 #20
0
def test_profit_is_registered(web3, chain, comp, vault, largerunningstrategy,
                              whale, gov, dai):

    stateOfStrat(largerunningstrategy, dai, comp)
    stateOfVault(vault, largerunningstrategy)
    #1m deposit
    amount = Wei('1000000 ether')
    deposit(amount, whale, dai, vault)
    harvest(largerunningstrategy, gov)

    #all money in vault
    assert largerunningstrategy.estimatedTotalAssets() > amount * 0.99
    stateOfStrat(largerunningstrategy, dai, comp)
    stateOfVault(vault, largerunningstrategy)

    sample = 500

    wait(sample, chain)
    harvest(largerunningstrategy, gov)
    stateOfStrat(largerunningstrategy, dai, comp)
    stateOfVault(vault, largerunningstrategy)

    debt = vault.strategies(largerunningstrategy)[5]
    returns = vault.strategies(largerunningstrategy)[6]
    assert returns > 0

    blocks_per_year = 2_300_000
    apr = returns / debt * (blocks_per_year / sample)
    print(f'implied apr: {apr:.8%}')

    assert apr > 0
コード例 #21
0
def test_live_status(web3, chain, live_vault, live_strategy,  comp,dai, samdev):
  stateOfStrat(live_strategy, dai, comp)
  stateOfVault(live_vault, live_strategy)

  genericStateOfStrat(live_strategy, dai, live_vault)
  genericStateOfVault(live_vault, dai)

  #withdraw(100,samdev, dai, live_vault)
  genericStateOfStrat(live_strategy, dai, live_vault)
  genericStateOfVault(live_vault, dai)
  wait(10, chain)
  print('\n Harvest')
  live_strategy.harvest({'from': samdev})
  
  genericStateOfStrat(live_strategy, dai, live_vault)
  genericStateOfVault(live_vault, dai)
  stateOfStrat(live_strategy, dai, comp)
  stateOfVault(live_vault, live_strategy)
  wait(10, chain)
  print('\n Harvest')
  live_strategy.harvest({'from': samdev})
  genericStateOfStrat(live_strategy, dai, live_vault)
  genericStateOfVault(live_vault, dai)

  stateOfStrat(live_strategy, dai, comp)
  stateOfVault(live_vault, live_strategy)
コード例 #22
0
def test_emergency_exit(web3, strategy, vault, whale, chain, dai, cdai, gov,
                        comp):

    amount1 = Wei('5000 ether')
    deposit(amount1, whale, dai, vault)

    amount1 = Wei('500 ether')
    deposit(amount1, gov, dai, vault)

    strategy.harvest({'from': gov})
    wait(30, chain)

    assert vault.emergencyShutdown() == False

    vault.setEmergencyShutdown(True, {"from": gov})
    assert vault.emergencyShutdown()

    stateOfStrat(strategy, dai, comp)
    stateOfVault(vault, strategy)
    strategy.harvest({'from': gov})
    print('\n Emergency shut down + harvest done')
    stateOfStrat(strategy, dai, comp)
    stateOfVault(vault, strategy)

    print('\n Withdraw All')
    vault.withdraw(vault.balanceOf(gov), {'from': gov})

    stateOfStrat(strategy, dai, comp)
    stateOfVault(vault, strategy)
コード例 #23
0
def test_apr_dai(web3, chain, comp, vault, enormousrunningstrategy, whale, gov, dai, strategist):
    enormousrunningstrategy.setProfitFactor(1, {"from": strategist} )
    assert(enormousrunningstrategy.profitFactor() == 1)

    enormousrunningstrategy.setMinCompToSell(1, {"from": gov})
    enormousrunningstrategy.setMinWant(0, {"from": gov})
    assert enormousrunningstrategy.minCompToSell() == 1

    startingBalance = vault.totalAssets()

    stateOfStrat(enormousrunningstrategy, dai, comp)
    stateOfVault(vault, enormousrunningstrategy)

    for i in range(6):
        
        waitBlock = 25
        print(f'\n----wait {waitBlock} blocks----')
        wait(waitBlock, chain)
        
        harvest(enormousrunningstrategy, strategist, vault)
        #stateOfStrat(enormousrunningstrategy, dai, comp)
        #stateOfVault(vault, enormousrunningstrategy)

        profit = (vault.totalAssets() - startingBalance).to('ether')
        strState = vault.strategies(enormousrunningstrategy)
        totalReturns = strState[6]
        totaleth = totalReturns.to('ether')
        print(f'Real Profit: {profit:.5f}')
        difff= profit-totaleth
        print(f'Diff: {difff}')

        blocks_per_year = 2_300_000
        assert startingBalance != 0
        time =(i+1)*waitBlock
        assert time != 0
        apr = (totalReturns/startingBalance) * (blocks_per_year / time)
        print(f'implied apr: {apr:.8%}')
    vault.withdraw(vault.balanceOf(whale), {'from': whale})
コード例 #24
0
def test_deposit_live_usdc(live_vault_usdc_030, live_strategy_usdc_030,
                           Contract, whale, web3, live_gov, accounts, chain,
                           cdai, comp, usdc, currency, samdev):
    strategist = samdev
    strategy = live_strategy_usdc_030
    vault = live_vault_usdc_030
    #  assert vault.governance() != live_gov
    #  vault.acceptGovernance({'from': live_gov})

    stateOfStrat(strategy, usdc, comp)
    genericStateOfVault(vault, usdc)
    genericStateOfStrat(strategy, usdc, vault)
    #print(vault.governance())

    assert vault.governance() == live_gov.address
    amount = 499000 * 1e6
    usdc.approve(vault, amount, {'from': whale})
    vault.deposit(amount, {'from': whale})

    strategy.harvest({'from': strategist})
    stateOfStrat(strategy, usdc, comp)
    genericStateOfVault(vault, usdc)
    genericStateOfStrat(strategy, usdc, vault)
コード例 #25
0
def test_shutdown(live_strategy_dai2,live_vault_dai2,live_strategy_usdc3, live_strategy_usdc4,live_vault_usdc3, live_strategy_dai4, Contract, usdc, web3,live_gov, accounts, chain, cdai, comp, dai, currency, whale,samdev):
    stateOfStrat(live_strategy_dai2, dai, comp)
    live_vault_dai2.revokeStrategy(live_strategy_dai2,  {'from': samdev})
    stateOfStrat(live_strategy_dai2, dai, comp)

    live_strategy_dai2.harvest({'from': samdev})
    live_strategy_dai2.harvest({'from': samdev})
    
    stateOfStrat(live_strategy_dai2, dai, comp)
    genericStateOfVault(live_vault_dai2, dai)
コード例 #26
0
def test_getting_too_close_to_liq(web3, chain, cdai, comp, vault,
                                  largerunningstrategy, whale, gov, dai):

    stateOfStrat(largerunningstrategy, dai, comp)
    stateOfVault(vault, largerunningstrategy)
    largerunningstrategy.setCollateralTarget(Wei('0.7498 ether'),
                                             {"from": gov})
    deposit(Wei('1000 ether'), whale, dai, vault)

    balanceBefore = vault.totalAssets()
    collat = 0
    assert largerunningstrategy.tendTrigger(1e18) == False

    largerunningstrategy.harvest({'from': gov})
    deposits, borrows = largerunningstrategy.getCurrentPosition()
    collat = borrows / deposits
    print(collat)

    stateOfStrat(largerunningstrategy, dai, comp)
    stateOfVault(vault, largerunningstrategy)
    assertCollateralRatio(largerunningstrategy)

    lastCol = collat

    while largerunningstrategy.tendTrigger(1e18) == False:
        cdai.mint(0, {"from": gov})
        waitBlock = 100
        wait(waitBlock, chain)
        deposits, borrows = largerunningstrategy.getCurrentPosition()
        collat = borrows / deposits
        assert collat > lastCol
        lastCol = collat
        print("Collat ratio: ", collat)
        print("Blocks to liq: ",
              largerunningstrategy.getblocksUntilLiquidation())

    largerunningstrategy.tend({'from': gov})

    largerunningstrategy.setCollateralTarget(Wei('0.73 ether'), {"from": gov})
    assert largerunningstrategy.tendTrigger(1e18) == False
    largerunningstrategy.tend({'from': gov})
    assertCollateralRatio(largerunningstrategy)
    stateOfStrat(largerunningstrategy, dai, comp)
    stateOfVault(vault, largerunningstrategy)
コード例 #27
0
def test_strat_sam(accounts, interface, web3, chain, vault, comp, whale,
                   YearnDaiCompStratV2, dai, gov):

    strategist_and_keeper = accounts[1]
    print(strategist_and_keeper)

    assert vault.governance() == gov
    assert vault.guardian() == gov
    assert vault.rewards() == gov
    assert vault.token() == dai

    # Deploy the Strategy
    strategy = strategist_and_keeper.deploy(YearnDaiCompStratV2, vault)

    # Addresses
    assert strategy.strategist() == strategist_and_keeper
    assert strategy.keeper() == strategist_and_keeper
    assert strategy.want() == vault.token()
    stateOfStrat(strategy, dai, comp)

    # Add strategy to the Vault
    assert vault.strategies(strategy) == [0, 0, 0, 0, 0, 0, 0]

    _debtLimit = Wei('1000000 ether')
    _rateLimit = Wei('1000000 ether')

    vault.addStrategy(strategy, _debtLimit, _rateLimit, 50, {"from": gov})

    assert vault.strategies(strategy) == [
        50,
        web3.eth.blockNumber,
        _debtLimit,
        _rateLimit,
        web3.eth.blockNumber,
        0,
        0,
    ]

    print(strategy._predictCompAccrued(), ' comp prediction')

    # Nothing was reported yet from the strategy
    assert vault.expectedReturn(strategy) == 0

    depositLimit = Wei('500000 ether')
    vault.setDepositLimit(depositLimit, {"from": gov})
    assert vault.depositLimit() == depositLimit

    #set compToSell

    # Provide funds to the Vault from whale

    # Test first with simply 5k as it is the current rate DAI/block

    amount = Wei('100000 ether')
    deposit(amount, whale, dai, vault)
    stateOfStrat(strategy, dai, comp)
    stateOfVault(vault, strategy)

    # Call harvest in Strategy only when harvestTrigger() --> (true)
    harvest(strategy, strategist_and_keeper)

    # assert( !strategy.harvestTrigger(0, {'from': strategist_and_keeper}))
    stateOfStrat(strategy, dai, comp)
    stateOfVault(vault, strategy)

    # now lets see 90k

    amount = Wei('320000 ether')
    deposit(amount, whale, dai, vault)
    stateOfStrat(strategy, dai, comp)
    stateOfVault(vault, strategy)

    harvest(strategy, strategist_and_keeper)

    stateOfStrat(strategy, dai, comp)
    stateOfVault(vault, strategy)

    # Claim COMP and check balance in strategy -> for testing _claimComp() needs to be public
    #strategy._claimComp({'from': strategist_and_keeper})
    #comp_balance = comp.balanceOf(strategy)

    #print(comp_balance.to('ether'), 'comp claimed')

    # Call harvest in Strategy only when harvestTrigger() --> (true)
    #harvest(strategy, strategist_and_keeper)

    stateOfStrat(strategy, dai, comp)
    stateOfVault(vault, strategy)

    #withdraw(1, strategy, whale, dai, vault)
    #vault.setEmergencyShutdown(True, {"from": gov})

    while strategy.harvestTrigger(0) == False:
        wait(25, chain)
        print(strategy._predictCompAccrued().to('ether'), ' comp prediction')

    #print('Emergency Exit')
    #strategy.setEmergencyExit({"from": gov})

    stateOfStrat(strategy, dai, comp)
    stateOfVault(vault, strategy)

    harvest(strategy, strategist_and_keeper)

    stateOfStrat(strategy, dai, comp)
    stateOfVault(vault, strategy)

    ##test migration
    print('test migration')
    strategy2 = strategist_and_keeper.deploy(YearnDaiCompStratV2, vault)
    vault.migrateStrategy(strategy, strategy2, {"from": gov})

    print('old strat')
    stateOfStrat(strategy, dai, comp)
    stateOfVault(vault, strategy)

    print('new strat')
    stateOfStrat(strategy2, dai, comp)
    stateOfVault(vault, strategy2)

    withdraw(1, whale, dai, vault)
    stateOfStrat(strategy2, dai, comp)
    stateOfVault(vault, strategy2)

    amount = Wei('320000 ether')
    deposit(amount, whale, dai, vault)
    stateOfStrat(strategy2, dai, comp)
    stateOfVault(vault, strategy2)

    harvest(strategy2, strategist_and_keeper)
    stateOfStrat(strategy2, dai, comp)
    stateOfVault(vault, strategy2)

    withdraw(1, whale, dai, vault)
    stateOfStrat(strategy2, dai, comp)
    stateOfVault(vault, strategy2)
コード例 #28
0
ファイル: full_run_test.py プロジェクト: Macarse/yearnv2
def test_full_live(web3, chain, comp, Vault, YearnDaiCompStratV2, dai, whale,
                   strategist, cdai):
    #our humble strategist is going to publish both the vault and the strategy

    # this is to mint small amount of dai reguarly to replicate people interacting with cdai contract
    dai.approve(cdai, 2**256 - 1, {"from": whale})

    starting_balance = dai.balanceOf(strategist)

    #deploy vault
    vault = strategist.deploy(Vault, dai, strategist, strategist,
                              "Ytest DAI Vault V2", "ytDAI2")

    #100k dai limit to begin with
    deposit_limit = Wei('1000000 ether')

    #set limit to the vault
    vault.setDepositLimit(deposit_limit, {"from": strategist})

    #deploy strategy
    strategy = strategist.deploy(YearnDaiCompStratV2, vault)

    strategy.setGasFactor(1, {"from": strategist})
    assert (strategy.gasFactor() == 1)
    strategy.setMinCompToSell(Wei('0.1 ether'), {"from": strategist})
    assert (strategy.minCompToSell() == Wei('0.1 ether'))

    #Current comp/eth rate
    compEthRate = strategy.getCompValInWei(Wei('1 ether'))
    print('Current comp/eth rate:', compEthRate)

    #enable the strategy
    rate_limit = deposit_limit
    vault.addStrategy(strategy, rate_limit, rate_limit, 50,
                      {"from": strategist})

    #our humble strategist deposits some test funds
    deposit(Wei('1000 ether'), strategist, dai, vault)
    stateOfStrat(strategy, dai, comp)
    stateOfVault(vault, strategy)
    assert strategy.estimatedTotalAssets() == 0

    harvest(strategy, strategist, vault)

    #whale deposits as well
    deposit(Wei('1000 ether'), whale, dai, vault)

    for i in range(15):
        #assertCollateralRatio(strategy)
        waitBlock = random.randint(10, 50)
        print(f'\n----wait {waitBlock} blocks----')
        chain.mine(waitBlock)

        #if harvest condition harvest. if tend tend
        print(strategy.predictCompAccrued().to('ether'), ' comp prediction')
        print(comp.balanceOf(strategy).to('ether'), ' comp in balance')
        harvest(strategy, strategist, vault)
        tend(strategy, strategist)
        something = True
        action = random.randint(0, 9)
        if action == 1:
            withdraw(random.randint(50, 100), whale, dai, vault)
        elif action == 2:
            withdraw(random.randint(50, 100), whale, dai, vault)
        elif action == 3:
            deposit(Wei(str(f'{random.randint(10000,100000)} ether')), whale,
                    dai, vault)
        elif action > 3 and action < 6:
            cdai.mint(1, {"from": whale})
        else:
            something = False

        if something:
            stateOfStrat(strategy, dai, comp)
            stateOfVault(vault, strategy)

    #strategist withdraws
    withdraw(1, strategist, dai, vault)
    stateOfStrat(strategy, dai, comp)
    stateOfVault(vault, strategy)

    profit = dai.balanceOf(strategist) - starting_balance

    print(Wei(profit).to('ether'), ' profit')
    print(vault.strategies(strategy)[6], ' total returns of strat')
コード例 #29
0
ファイル: test_strat.py プロジェクト: Macarse/yearnv2
def test_strat_sam(accounts, interface, web3, chain, Vault,
                   YearnDaiCompStratV2):
    gov = accounts[0]
    print(gov)
    strategist_and_keeper = accounts[1]
    print(strategist_and_keeper)

    dai = interface.ERC20('0x6b175474e89094c44da98b954eedeac495271d0f')
    cdai = interface.ERC20('0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643')
    comp = interface.ERC20('0xc00e94Cb662C3520282E6f5717214004A7f26888')
    comptroller = interface.ComptrollerI(
        '0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B')
    # Current COMP speeds
    print('COMP speed: ', comptroller.compSpeeds(cdai))

    ydai = interface.ERC20('0x16de59092dae5ccf4a1e6439d611fd0653f0bd01')
    whale = accounts.at("0xBE0eB53F46cd790Cd13851d5EFf43D12404d33E8",
                        force=True)

    # Deploy the Vault
    vault = gov.deploy(Vault, dai, gov, gov, "Yearn DAI v2", "y2DAI")

    assert vault.governance() == gov
    assert vault.guardian() == gov
    assert vault.rewards() == gov
    assert vault.token() == dai

    # Deploy the Strategy
    strategy = strategist_and_keeper.deploy(YearnDaiCompStratV2, vault)

    # Addresses
    assert strategy.strategist() == strategist_and_keeper
    assert strategy.keeper() == strategist_and_keeper
    assert strategy.want() == vault.token()
    stateOfStrat(strategy, dai)

    # Test current price for COMP and DAI using Chainlink
    lastExchangeRate = strategy.getLatestExchangeRate()
    print('Current exchange rate (COMP/DAI): ', lastExchangeRate)

    # Add strategy to the Vault
    assert vault.strategies(strategy) == [0, 0, 0, 0, 0, 0, 0]

    _debtLimit = Wei('1000000 ether')
    _rateLimit = Wei('1000000 ether')

    vault.addStrategy(strategy, _debtLimit, _rateLimit, 50, {"from": gov})

    assert vault.strategies(strategy) == [
        50,
        web3.eth.blockNumber,
        _debtLimit,
        _rateLimit,
        web3.eth.blockNumber,
        0,
        0,
    ]

    print(strategy._predictCompAccrued(), ' comp prediction')

    # Nothing was reported yet from the strategy
    assert vault.expectedReturn(strategy) == 0
    stateOfStrat(strategy, dai)

    depositLimit = Wei('500000 ether')
    vault.setDepositLimit(depositLimit, {"from": gov})
    assert vault.depositLimit() == depositLimit

    # Provide funds to the Vault from whale

    # Test first with simply 5k as it is the current rate DAI/block

    amount = Wei('100000 ether')
    deposit(amount, whale, dai, vault)
    stateOfStrat(strategy, dai)
    stateOfVault(vault, strategy)

    # Call harvest in Strategy only when harvestTrigger() --> (true)
    harvest(strategy, strategist_and_keeper)

    # assert( !strategy.harvestTrigger(0, {'from': strategist_and_keeper}))
    stateOfStrat(strategy, dai)
    stateOfVault(vault, strategy)

    # now lets see 90k

    amount = Wei('320000 ether')
    deposit(amount, whale, dai, vault)
    stateOfStrat(strategy, dai)
    stateOfVault(vault, strategy)

    harvest(strategy, strategist_and_keeper)

    stateOfStrat(strategy, dai)
    stateOfVault(vault, strategy)

    # Call harvest in Strategy only when harvestTrigger() --> (true)
    #harvest(strategy, strategist_and_keeper)

    stateOfStrat(strategy, dai)
    stateOfVault(vault, strategy)

    #withdraw(1, strategy, whale, dai, vault)
    #vault.setEmergencyShutdown(True, {"from": gov})

    while strategy.harvestTrigger(0) == False:
        wait(25, chain)
        print(strategy._predictCompAccrued().to('ether'), ' comp prediction')

    #print('Emergency Exit')
    #strategy.setEmergencyExit({"from": gov})

    # Claim COMP and check balance in strategy -> for testing _claimComp() needs to be public
    strategy._claimComp({'from': strategist_and_keeper})
    comp_balance = comp.balanceOf(strategy)
    print(comp_balance.to('ether'), 'comp claimed')

    stateOfStrat(strategy, dai)
    stateOfVault(vault, strategy)

    harvest(strategy, strategist_and_keeper)

    stateOfStrat(strategy, dai)
    stateOfVault(vault, strategy)

    ##test migration
    print('test migration')
    strategy2 = strategist_and_keeper.deploy(YearnDaiCompStratV2, vault)
    vault.migrateStrategy(strategy, strategy2, {"from": gov})

    print('old strat')
    stateOfStrat(strategy, dai)
    stateOfVault(vault, strategy)

    print('new strat')
    stateOfStrat(strategy2, dai)
    stateOfVault(vault, strategy2)

    withdraw(1, whale, dai, vault)
    stateOfStrat(strategy2, dai)
    stateOfVault(vault, strategy2)

    amount = Wei('320000 ether')
    deposit(amount, whale, dai, vault)
    stateOfStrat(strategy2, dai)
    stateOfVault(vault, strategy2)

    harvest(strategy2, strategist_and_keeper)
    stateOfStrat(strategy2, dai)
    stateOfVault(vault, strategy2)

    withdraw(1, whale, dai, vault)
    stateOfStrat(strategy2, dai)
    stateOfVault(vault, strategy2)