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)
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)
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)