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
59 changes: 55 additions & 4 deletions contracts/RouterStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ interface IVault is IERC20 {

function pricePerShare() external view returns (uint256);

function totalAssets() external view returns (uint256);

function lockedProfit() external view returns (uint256);

function lockedProfitDegradation() external view returns (uint256);

function lastReport() external view returns (uint256);

function withdraw(
uint256 amount,
address account,
Expand Down Expand Up @@ -205,6 +213,10 @@ contract RouterStrategy is BaseStrategy {
}
}

function withdrawFromYVault(uint256 _amount) external onlyVaultManagers {
_withdrawFromYVault(_amount);
}

function _withdrawFromYVault(uint256 _amount) internal {
if (_amount == 0) {
return;
Expand Down Expand Up @@ -286,13 +298,52 @@ contract RouterStrategy is BaseStrategy {
view
returns (uint256)
{
return amount.mul(10**yVault.decimals()).div(yVault.pricePerShare());
return _valueInYVaultShares(amount);
}

function valueOfInvestment() public view virtual returns (uint256) {
return
yVault.balanceOf(address(this)).mul(yVault.pricePerShare()).div(
10**yVault.decimals()
return _yVaultSharesValue(yVault.balanceOf(address(this)));
}

function _valueInYVaultShares(uint256 value)
internal
view
returns (uint256)
{
uint256 totalSupply = yVault.totalSupply();
uint256 freeFunds = _calculateYVaultFreeFunds();
if (freeFunds == 0) return 0;
return (value.mul(totalSupply).div(freeFunds));
}

function _yVaultSharesValue(uint256 shares)
internal
view
returns (uint256)
{
uint256 totalSupply = yVault.totalSupply();
if (totalSupply == 0) return shares;

uint256 freeFunds = _calculateYVaultFreeFunds();
return (shares.mul(freeFunds).div(totalSupply));
}

function _calculateYVaultFreeFunds()
private
view
returns (uint256 freeFunds)
{
freeFunds = yVault.totalAssets();
uint256 lockedFundsRatio =
(block.timestamp.sub(yVault.lastReport())).mul(
yVault.lockedProfitDegradation()
);

if (lockedFundsRatio < 10**18) {
uint256 lockedProfit = yVault.lockedProfit();
freeFunds = freeFunds.sub(
lockedProfit.sub(lockedFundsRatio.mul(lockedProfit).div(10**18))
);
}
}
}
203 changes: 0 additions & 203 deletions tests/SynthetixRouter/test_sbtc_router_deploy.py

This file was deleted.

16 changes: 10 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def destination_vault():

@pytest.fixture
def weth_whale(accounts):
yield accounts.at("0xc1aae9d18bbe386b102435a8632c8063d31e747c", True)
yield accounts.at("0x2feb1512183545f48f6b9c5b4ebfcaf49cfca6f3", True)


@pytest.fixture
Expand All @@ -89,11 +89,11 @@ def token():


@pytest.fixture
def amount(accounts, token, user):
amount = 10_000 * 10 ** token.decimals()
def amount(accounts, token, user, weth_whale):
amount = 1000 * 10 ** token.decimals()
# In order to get some funds for the token you are about to use,
# it impersonate an exchange address to use it's funds.
reserve = accounts.at("0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643", force=True)
reserve = accounts.at(weth_whale, force=True)
token.transfer(user, amount, {"from": reserve})
yield amount

Expand Down Expand Up @@ -146,7 +146,9 @@ def strategy(
if ZERO_ADDRESS == strat_address:
break

origin_vault.updateStrategyDebtRatio(strat_address, 0, {"from": gov})
if origin_vault.strategies(strat_address)['debtRatio'] > 0:
origin_vault.updateStrategyDebtRatio(strat_address, 0, {"from": gov})
Contract(strat_address).harvest({"from":gov})

strategy.setHealthCheck(health_check, {"from": origin_vault.governance()})
origin_vault.addStrategy(strategy, 10_000, 0, 2 ** 256 - 1, 0, {"from": gov})
Expand All @@ -169,7 +171,9 @@ def unique_strategy(
if ZERO_ADDRESS == strat_address:
break

yvweth_032.updateStrategyDebtRatio(strat_address, 0, {"from": gov})
if yvweth_032.strategies(strat_address)['debtRatio'] > 0:
yvweth_032.updateStrategyDebtRatio(strat_address, 0, {"from": gov})
Contract(strat_address).harvest({"from":gov})

yvweth_032.setPerformanceFee(0, {"from": gov})
yvweth_032.setManagementFee(0, {"from": gov})
Expand Down
13 changes: 8 additions & 5 deletions tests/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from brownie import chain, Wei, reverts, Contract, ZERO_ADDRESS


def move_funds(vault, dest_vault, strategy, gov, weth, weth_whale):
def move_funds(vault, dest_vault, strategy, gov, weth, weth_whale, RELATIVE_APPROX):
print(strategy.name())

strategy.harvest({"from": gov})
Expand All @@ -27,9 +27,9 @@ def move_funds(vault, dest_vault, strategy, gov, weth, weth_whale):
chain.sleep(3600 * 8)
chain.mine(1)

assert vault.strategies(strategy).dict()["totalGain"] == total_gain
assert vault.strategies(strategy).dict()["totalLoss"] == 0
assert vault.strategies(strategy).dict()["totalDebt"] == 0
assert pytest.approx(vault.strategies(strategy).dict()["totalGain"], rel=RELATIVE_APPROX) == total_gain
assert pytest.approx(vault.strategies(strategy).dict()["totalLoss"], rel=RELATIVE_APPROX) == 0
assert pytest.approx(vault.strategies(strategy).dict()["totalDebt"], rel=RELATIVE_APPROX) == 0


def test_original_strategy(
Expand All @@ -42,9 +42,10 @@ def test_original_strategy(
gov,
token,
weth_whale,
RELATIVE_APPROX
):

move_funds(origin_vault, destination_vault, strategy, gov, token, weth_whale)
move_funds(origin_vault, destination_vault, strategy, gov, token, weth_whale, RELATIVE_APPROX)


def test_cloned_strategy(
Expand All @@ -57,6 +58,7 @@ def test_cloned_strategy(
gov,
token,
weth_whale,
RELATIVE_APPROX
):

clone_tx = strategy.cloneRouter(
Expand All @@ -80,6 +82,7 @@ def test_cloned_strategy(
gov,
token,
weth_whale,
RELATIVE_APPROX
)


Expand Down
Loading