Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions brownie-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ autofetch_sources: True

# require OpenZepplin Contracts
dependencies:
- yearn/yearn-vaults@0.4.2
- yearn/yearn-vaults@0.3.0
- OpenZeppelin/openzeppelin-contracts@3.1.0

# path remapping to support imports from GitHub/NPM
compiler:
solc:
version: 0.6.12
remappings:
- "@yearnvaults=yearn/yearn-vaults@0.4.2"
- "@yearnvaults=yearn/yearn-vaults@0.3.0"
- "@openzeppelin=OpenZeppelin/openzeppelin-contracts@3.1.0"

reports:
Expand Down
35 changes: 6 additions & 29 deletions contracts/RouterStrategy.sol → contracts/RouterStrategy030.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface IVault is IERC20 {
) external returns (uint256);
}

contract RouterStrategy is BaseStrategy {
contract RouterStrategy030 is BaseStrategy {
using SafeERC20 for IERC20;
using Address for address;
using SafeMath for uint256;
Expand All @@ -46,7 +46,11 @@ contract RouterStrategy is BaseStrategy {
}

modifier onlyManagement() {
require(msg.sender == governance() || msg.sender == vault.management());
require(
msg.sender == governance() ||
msg.sender ==
address(0x16388463d60FFE0661Cf7F1f31a7D658aC790ff7)
);
_;
}

Expand All @@ -65,10 +69,6 @@ contract RouterStrategy is BaseStrategy {
return balanceOfWant().add(valueOfInvestment());
}

function delegatedAssets() external view override returns (uint256) {
return vault.strategies(address(this)).totalDebt;
}

function prepareReturn(uint256 _debtOutstanding)
internal
override
Expand Down Expand Up @@ -160,19 +160,6 @@ contract RouterStrategy is BaseStrategy {
yVault.withdraw(sharesToWithdraw, address(this), maxLoss);
}

function liquidateAllPositions()
internal
override
returns (uint256 _amountFreed)
{
return
yVault.withdraw(
yVault.balanceOf(address(this)),
address(this),
maxLoss
);
}

function prepareMigration(address _newStrategy) internal override {
IERC20(yVault).safeTransfer(
_newStrategy,
Expand All @@ -191,16 +178,6 @@ contract RouterStrategy is BaseStrategy {
return ret;
}

function ethToWant(uint256 _amtInWei)
public
view
virtual
override
returns (uint256)
{
return _amtInWei;
}

function setMaxLoss(uint256 _maxLoss) public onlyManagement {
maxLoss = _maxLoss;
}
Expand Down
36 changes: 28 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ def keeper(accounts):
yield accounts[5]


@pytest.fixture
def yvdai_030():
yield Contract("0x19D3364A399d251E894aC732651be8B0E4e85001")


@pytest.fixture
def yvdai_042():
yield Contract("0x63739d137EEfAB1001245A8Bd1F3895ef3e186E7")


@pytest.fixture
def yvweth_032():
yield Contract("0xa9fE4601811213c340e850ea305481afF02f5b28")
Expand All @@ -47,6 +57,11 @@ def yvweth_042():
yield Contract("0xa258C4606Ca8206D8aA700cE2143D7db854D168c")


@pytest.fixture
def dai_whale(accounts):
yield accounts.at("0x5d3a536e4d6dbd6114cc1ead35777bab948e3643", True)


@pytest.fixture
def weth_whale(accounts):
yield accounts.at("0xc1aae9d18bbe386b102435a8632c8063d31e747c", True)
Expand All @@ -68,6 +83,11 @@ def amount(accounts, token, user):
yield amount


@pytest.fixture
def dai():
yield Contract("0x6b175474e89094c44da98b954eedeac495271d0f")


@pytest.fixture
def weth():
yield Contract("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
Expand All @@ -91,23 +111,23 @@ def vault(pm, gov, rewards, guardian, management, token):


@pytest.fixture
def strategy(strategist, keeper, yvweth_032, yvweth_042, RouterStrategy, gov):
def dai_strategy(strategist, keeper, yvdai_030, yvdai_042, RouterStrategy030, gov):
strategy = strategist.deploy(
RouterStrategy, yvweth_032, yvweth_042, "Route yvWETH 042"
RouterStrategy030, yvdai_030, yvdai_042, "Route yvDAI 042"
)
strategy.setKeeper(keeper)

for i in range(0, 20):
strat_address = yvweth_032.withdrawalQueue(i)
strat_address = yvdai_030.withdrawalQueue(i)
if ZERO_ADDRESS == strat_address:
break

yvweth_032.updateStrategyDebtRatio(strat_address, 0, {"from": gov})
yvdai_030.updateStrategyDebtRatio(strat_address, 0, {"from": gov})

yvweth_032.setPerformanceFee(0, {"from": gov})
yvweth_032.setManagementFee(0, {"from": gov})
yvweth_032.addStrategy(strategy, 10_000, 0, 2 ** 256 - 1, 0, {"from": gov})
yvweth_032.setDepositLimit(0, {"from": gov})
yvdai_030.setPerformanceFee(0, {"from": gov})
yvdai_030.setManagementFee(0, {"from": gov})
yvdai_030.addStrategy(strategy, 9_924, 0, 0, {"from": gov})
yvdai_030.setDepositLimit(0, {"from": gov})

yield strategy

Expand Down
31 changes: 31 additions & 0 deletions tests/test_dai_profit_emergency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest
from brownie import Contract, ZERO_ADDRESS, Wei, chain


def test_dai_profit_emergency(yvdai_030, yvdai_042, dai_strategy, gov, dai, dai_whale):

strategy = dai_strategy
# Move only gen lender funds to the new strat
strat = Contract(yvdai_030.withdrawalQueue(0))
strat.harvest({"from": gov})
print(f"dai balance in vault {dai.balanceOf(yvdai_030)/1e18}")

strategy.harvest({"from": gov})
assert strategy.balanceOfWant() == 0
assert strategy.valueOfInvestment() > 0

# Send profit to 042
prev_value = strategy.valueOfInvestment()
dai.transfer(yvdai_042, Wei("100_000 ether"), {"from": dai_whale})
assert strategy.valueOfInvestment() > prev_value

strategy.setEmergencyExit({"from": gov})
strategy.harvest({"from": gov})
chain.sleep(3600 * 8)
chain.mine(1)

total_gain = yvdai_030.strategies(strategy).dict()["totalGain"]
assert total_gain > 0
assert yvdai_030.strategies(strategy).dict()["totalLoss"] == 0
assert strategy.balanceOfWant() < Wei("1 ether")
assert strategy.valueOfInvestment() < Wei("1 ether")
32 changes: 32 additions & 0 deletions tests/test_dai_profit_revoke.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest
from brownie import Contract, ZERO_ADDRESS, Wei, chain


def test_dai_profit_revoke(yvdai_030, yvdai_042, dai_strategy, gov, dai, dai_whale):

strategy = dai_strategy

# Move only gen lender funds to the new strat
strat = Contract(yvdai_030.withdrawalQueue(0))
strat.harvest({"from": gov})
print(f"dai balance in vault {dai.balanceOf(yvdai_030)/1e18}")

strategy.harvest({"from": gov})
assert strategy.balanceOfWant() == 0
assert strategy.valueOfInvestment() > 0

# Send profit to 042
prev_value = strategy.valueOfInvestment()
dai.transfer(yvdai_042, Wei("10 ether"), {"from": dai_whale})
assert strategy.valueOfInvestment() > prev_value

yvdai_030.revokeStrategy(strategy, {"from": gov})
strategy.harvest({"from": gov})
chain.sleep(3600 * 8)
chain.mine(1)

total_gain = yvdai_030.strategies(strategy).dict()["totalGain"]
assert total_gain > 0
assert yvdai_030.strategies(strategy).dict()["totalLoss"] == 0
assert strategy.balanceOfWant() < Wei("1 ether")
assert strategy.valueOfInvestment() < Wei("1 ether")
33 changes: 0 additions & 33 deletions tests/test_migration.py

This file was deleted.

36 changes: 36 additions & 0 deletions tests/test_move_dai_funds_to_042.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from brownie import Contract, ZERO_ADDRESS, Wei, chain


def test_move_dai_funds_to_042(yvdai_030, yvdai_042, dai_strategy, gov, dai, dai_whale):
# hack :)
strategy = dai_strategy

# Move only gen lender funds to the new strat
strat = Contract(yvdai_030.withdrawalQueue(0))
strat.harvest({"from": gov})
print(f"dai balance in vault {dai.balanceOf(yvdai_030)/1e18}")

strategy.harvest({"from": gov})
assert strategy.balanceOfWant() == 0
assert strategy.valueOfInvestment() > 0

# Send profit to 042
prev_value = strategy.valueOfInvestment()
dai.transfer(yvdai_042, Wei("1000 ether"), {"from": dai_whale})
assert strategy.valueOfInvestment() > prev_value

strategy.harvest({"from": gov})

total_gain = yvdai_030.strategies(strategy).dict()["totalGain"]
assert total_gain > 0
assert yvdai_030.strategies(strategy).dict()["totalLoss"] == 0

yvdai_030.revokeStrategy(strategy, {"from": gov})
strategy.harvest({"from": gov})

assert yvdai_030.strategies(strategy).dict()["totalGain"] - total_gain < Wei(
"1 ether"
)
assert yvdai_030.strategies(strategy).dict()["totalLoss"] == 0
assert yvdai_030.strategies(strategy).dict()["totalDebt"] == 0
44 changes: 0 additions & 44 deletions tests/test_move_funds_to_042.py

This file was deleted.

Loading