Skip to content

Commit ffa5fd2

Browse files
author
wavey0x
committed
feat: sweep from loss checker
feat: sweep from loss checker
1 parent e70b08f commit ffa5fd2

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

contracts/LossOnFeeChecker.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
pragma solidity 0.6.12;
22
pragma experimental ABIEncoderV2;
33

4+
import {
5+
SafeERC20,
6+
IERC20
7+
} from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
8+
49
interface IVault {
510
struct StrategyParams {
611
uint performanceFee;
@@ -27,9 +32,11 @@ interface IStrategy {
2732
/// @notice Designed to prevent Management fees from creating lossy reports on Yearn vaults with API < 0.3.5
2833
/// @dev Begining with vaults API v0.3.5 management fees are adjust dynamically on report to prevent loss
2934
contract LossOnFeeChecker {
35+
using SafeERC20 for IERC20;
3036

3137
uint constant MAX_BPS = 10_000;
3238
uint constant SECS_PER_YEAR = 31_557_600;
39+
mapping(address=>bool) public approvedSweepers;
3340

3441
/// @notice Check if harvest does not contain a loss after fees
3542
/// @dev should be called automically report transaction
@@ -83,5 +90,17 @@ contract LossOnFeeChecker {
8390
return governanceFee + grossLoss;
8491
}
8592
}
93+
94+
function sweep(address _token, uint _amount) external {
95+
require(approvedSweepers[msg.sender], "!approved");
96+
IERC20(_token).transfer(msg.sender, _amount);
97+
}
98+
99+
function approveSweepers(address _sweeper, bool _approved) external {
100+
address ychad = 0xFEB4acf3df3cDEA7399794D0869ef76A6EfAff52;
101+
address brain = 0x16388463d60FFE0661Cf7F1f31a7D658aC790ff7;
102+
require(msg.sender == ychad || msg.sender == brain);
103+
approvedSweepers[_sweeper] = _approved;
104+
}
86105
}
87106

contracts/RouterStrategy.sol

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import "@openzeppelin/contracts/math/Math.sol";
1414

1515
interface ILossChecker {
1616
function checkLoss(uint, uint) external view returns (uint);
17+
function sweep(address, uint) external;
1718
}
1819

1920
interface IVault is IERC20 {
@@ -169,7 +170,11 @@ contract RouterStrategy is BaseStrategy {
169170
_loss = 0;
170171
}
171172

172-
require(lossChecker.checkLoss(_profit, _loss) <= feeLossTolerance, "TooLossy!");
173+
uint expectedLoss = lossChecker.checkLoss(_profit, _loss);
174+
if (expectedLoss > feeLossTolerance){
175+
require(want.balanceOf(address(lossChecker)) > expectedLoss, "LossyWithFees");
176+
lossChecker.sweep(address(want), expectedLoss);
177+
}
173178
}
174179

175180
function adjustPosition(uint256 _debtOutstanding)

tests/test_operation_steth.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@ def test_migrate(origin_vault, destination_vault, strategy, gov, loss_checker):
2626
whale = accounts.at('0x99ac10631F69C753DDb595D074422a0922D9056B', force=True)
2727
want = Contract(origin_vault.token(),owner=whale)
2828
# want.transfer(strategy, expected_loss + 1e17)
29-
assert False
3029

3130
totalShares = origin_vault.totalSupply()
3231
tx = strategy.harvest({"from": gov})
3332
totalSharesAfter = origin_vault.totalSupply()
3433
assert totalSharesAfter <= totalShares
3534

3635
print(tx.events['Harvested'])
37-
assert False
3836
# origin_vault.updateStrategyDebtRatio(strategy, 10_000, {'from':gov})
3937

4038

0 commit comments

Comments
 (0)