diff --git a/contracts/strategy/StrategyBaseV2.sol b/contracts/strategy/StrategyBaseV2.sol index 8599fd0..14c9c28 100644 --- a/contracts/strategy/StrategyBaseV2.sol +++ b/contracts/strategy/StrategyBaseV2.sol @@ -187,8 +187,7 @@ abstract contract StrategyBaseV2 is IStrategyV2, ControllableV3 { _asset, balance, expectedWithdrewUSD, - assetPrice, - _splitter + assetPrice ); } diff --git a/contracts/strategy/StrategyBaseV3.sol b/contracts/strategy/StrategyBaseV3.sol index 59efbd5..ea9190d 100644 --- a/contracts/strategy/StrategyBaseV3.sol +++ b/contracts/strategy/StrategyBaseV3.sol @@ -187,8 +187,7 @@ abstract contract StrategyBaseV3 is IStrategyV3, ControllableV3 { _asset, balance, expectedWithdrewUSD, - assetPrice, - _splitter + assetPrice ); } diff --git a/contracts/strategy/StrategyLib.sol b/contracts/strategy/StrategyLib.sol index 8260ebf..c7b661a 100644 --- a/contracts/strategy/StrategyLib.sol +++ b/contracts/strategy/StrategyLib.sol @@ -16,7 +16,9 @@ library StrategyLib { // ************************************************************* /// @dev Denominator for fee calculation. - uint internal constant FEE_DENOMINATOR = 100_000; + uint internal constant DENOMINATOR = 100_000; + + uint internal constant CHECK_WITHDRAW_IMPACT_TOLERANCE = 1_000; // ************************************************************* // EVENTS @@ -37,8 +39,6 @@ library StrategyLib { string internal constant DENIED = "SB: Denied"; string internal constant TOO_HIGH = "SB: Too high"; string internal constant WRONG_VALUE = "SB: Wrong value"; - /// @dev Denominator for compound ratio - uint internal constant COMPOUND_DENOMINATOR = 100_000; // ************************************************************* // CHECKS AND EMITS @@ -46,7 +46,7 @@ library StrategyLib { function _checkCompoundRatioChanged(address controller, uint oldValue, uint newValue) external { onlyPlatformVoter(controller); - require(newValue <= COMPOUND_DENOMINATOR, TOO_HIGH); + require(newValue <= DENOMINATOR, TOO_HIGH); emit CompoundRatioChanged(oldValue, newValue); } @@ -110,16 +110,14 @@ library StrategyLib { address _asset, uint balanceBefore, uint expectedWithdrewUSD, - uint assetPrice, - address _splitter + uint assetPrice ) public view returns (uint balance) { balance = IERC20(_asset).balanceOf(address(this)); if (assetPrice != 0 && expectedWithdrewUSD != 0) { - uint withdrew = balance > balanceBefore ? balance - balanceBefore : 0; uint withdrewUSD = withdrew * assetPrice / 1e18; uint difference = expectedWithdrewUSD > withdrewUSD ? expectedWithdrewUSD - withdrewUSD : 0; - require(difference * 1e18 / expectedWithdrewUSD < 1e16, TOO_HIGH); + require(difference * DENOMINATOR / expectedWithdrewUSD < CHECK_WITHDRAW_IMPACT_TOLERANCE, TOO_HIGH); } } @@ -147,8 +145,7 @@ library StrategyLib { _asset, balanceBefore, expectedWithdrewUSD, - assetPrice, - _splitter + assetPrice ); if (balance != 0) { diff --git a/contracts/strategy/StrategyLib2.sol b/contracts/strategy/StrategyLib2.sol index b4379e2..a336381 100644 --- a/contracts/strategy/StrategyLib2.sol +++ b/contracts/strategy/StrategyLib2.sol @@ -18,12 +18,11 @@ library StrategyLib2 { // ************************************************************* /// @dev Denominator for fee calculation. - uint internal constant FEE_DENOMINATOR = 100_000; + uint internal constant DENOMINATOR = 100_000; /// @notice 10% of total profit is sent to {performanceReceiver} before compounding uint internal constant DEFAULT_PERFORMANCE_FEE = 10_000; address internal constant DEFAULT_PERF_FEE_RECEIVER = 0x9Cc199D4353b5FB3e6C8EEBC99f5139e0d8eA06b; - /// @dev Denominator for compound ratio - uint internal constant COMPOUND_DENOMINATOR = 100_000; + uint internal constant CHECK_WITHDRAW_IMPACT_TOLERANCE = 1_000; // ************************************************************* // ERRORS @@ -63,9 +62,9 @@ library StrategyLib2 { function _checkSetupPerformanceFee(address controller, uint fee_, address receiver_, uint ratio_) internal { onlyGovernance(controller); - require(fee_ <= FEE_DENOMINATOR, TOO_HIGH); + require(fee_ <= DENOMINATOR, TOO_HIGH); require(receiver_ != address(0), WRONG_VALUE); - require(ratio_ <= FEE_DENOMINATOR, TOO_HIGH); + require(ratio_ <= DENOMINATOR, TOO_HIGH); emit PerformanceFeeChanged(fee_, receiver_, ratio_); } @@ -75,7 +74,7 @@ library StrategyLib2 { function _changeCompoundRatio(IStrategyV3.BaseState storage baseState, address controller, uint newValue) external { onlyPlatformVoterOrGov(controller); - require(newValue <= COMPOUND_DENOMINATOR, TOO_HIGH); + require(newValue <= DENOMINATOR, TOO_HIGH); uint oldValue = baseState.compoundRatio; baseState.compoundRatio = newValue; @@ -146,17 +145,15 @@ library StrategyLib2 { address _asset, uint balanceBefore, uint expectedWithdrewUSD, - uint assetPrice, - address _splitter + uint assetPrice ) public view returns (uint balance) { balance = IERC20(_asset).balanceOf(address(this)); if (assetPrice != 0 && expectedWithdrewUSD != 0) { uint withdrew = balance > balanceBefore ? balance - balanceBefore : 0; uint withdrewUSD = withdrew * assetPrice / 1e18; - uint priceChangeTolerance = ITetuVaultV2(ISplitter(_splitter).vault()).withdrawFee(); uint difference = expectedWithdrewUSD > withdrewUSD ? expectedWithdrewUSD - withdrewUSD : 0; - require(difference * FEE_DENOMINATOR / expectedWithdrewUSD <= priceChangeTolerance, TOO_HIGH); + require(difference * DENOMINATOR / expectedWithdrewUSD < CHECK_WITHDRAW_IMPACT_TOLERANCE, TOO_HIGH); } } @@ -184,8 +181,7 @@ library StrategyLib2 { _asset, balanceBefore, expectedWithdrewUSD, - assetPrice, - _splitter + assetPrice ); if (balance != 0) { diff --git a/contracts/test/MockStrategy.sol b/contracts/test/MockStrategy.sol index 4aceae4..7d7653b 100644 --- a/contracts/test/MockStrategy.sol +++ b/contracts/test/MockStrategy.sol @@ -44,7 +44,7 @@ contract MockStrategy is StrategyBaseV2 { IERC20(asset).transfer(controller(), _slippage); } if (lastEarned != 0) { - uint toCompound = lastEarned * compoundRatio / StrategyLib.COMPOUND_DENOMINATOR; + uint toCompound = lastEarned * compoundRatio / StrategyLib.DENOMINATOR; MockToken(asset).mint(address(this), toCompound); address forwarder = IController(controller()).forwarder(); if (forwarder != address(0)) { @@ -188,9 +188,8 @@ contract MockStrategy is StrategyBaseV2 { address _asset, uint balanceBefore, uint investedAssetsUSD, - uint assetPrice, - address _splitter + uint assetPrice ) external view returns (uint balance) { - return StrategyLib.checkWithdrawImpact(_asset, balanceBefore, investedAssetsUSD, assetPrice, _splitter); + return StrategyLib.checkWithdrawImpact(_asset, balanceBefore, investedAssetsUSD, assetPrice); } } diff --git a/contracts/test/MockStrategyV3.sol b/contracts/test/MockStrategyV3.sol index 6b780a3..ec7ebaf 100644 --- a/contracts/test/MockStrategyV3.sol +++ b/contracts/test/MockStrategyV3.sol @@ -45,7 +45,7 @@ contract MockStrategyV3 is StrategyBaseV3 { IERC20(asset).transfer(controller(), _slippage); } if (lastEarned != 0) { - uint toCompound = lastEarned * baseState.compoundRatio / StrategyLib2.COMPOUND_DENOMINATOR; + uint toCompound = lastEarned * baseState.compoundRatio / StrategyLib2.DENOMINATOR; MockToken(asset).mint(address(this), toCompound); address forwarder = IController(controller()).forwarder(); if (forwarder != address(0)) { @@ -189,9 +189,8 @@ contract MockStrategyV3 is StrategyBaseV3 { address _asset, uint balanceBefore, uint investedAssetsUSD, - uint assetPrice, - address _splitter + uint assetPrice ) external view returns (uint balance) { - return StrategyLib2.checkWithdrawImpact(_asset, balanceBefore, investedAssetsUSD, assetPrice, _splitter); + return StrategyLib2.checkWithdrawImpact(_asset, balanceBefore, investedAssetsUSD, assetPrice); } } diff --git a/test/vault/CheckWithdrawImpactTest.ts b/test/vault/CheckWithdrawImpactTest.ts index 12d80f6..3e13b51 100644 --- a/test/vault/CheckWithdrawImpactTest.ts +++ b/test/vault/CheckWithdrawImpactTest.ts @@ -105,8 +105,7 @@ describe("Tests for StrategyBaseV2._checkWithdrawImpact", function () { asset.address, balanceBeforeWithdraw, investedAssetsUSD, - assetPrice, - splitter.address + assetPrice ); } //endregion Utils diff --git a/test/vault/SplitterForBaseStrategyV3Tests.ts b/test/vault/SplitterForBaseStrategyV3Tests.ts index 1813c02..b2cd6ef 100644 --- a/test/vault/SplitterForBaseStrategyV3Tests.ts +++ b/test/vault/SplitterForBaseStrategyV3Tests.ts @@ -19,7 +19,6 @@ import { import {Misc} from "../../scripts/utils/Misc"; import {parseUnits} from "ethers/lib/utils"; - const {expect} = chai; chai.use(chaiAsPromised); @@ -854,7 +853,7 @@ describe("SplitterForBaseStrategyV3Tests", function () { }); }); - it("should not withdraw when MockStrategy has UseTrueExpectedWithdraw enabled, but in real slippage exist", async () => { + it("should not withdraw when MockStrategyV3 has UseTrueExpectedWithdraw enabled, but in real slippage exist", async () => { const insurance = await vault.insurance(); await strategy.init(controller.address, splitter.address); @@ -878,7 +877,7 @@ describe("SplitterForBaseStrategyV3Tests", function () { // console.log('insuranceBefore', insuranceBefore) await strategy.setUseTrueExpectedWithdraw(true) - await strategy.setSlippage(10); + await strategy.setSlippage(1_000); await expect(vault.withdrawAll()).revertedWith('SB: Too high')