diff --git a/contracts/interfaces/IStrategyV3.sol b/contracts/interfaces/IStrategyV3.sol index c79fdff..f6b443f 100644 --- a/contracts/interfaces/IStrategyV3.sol +++ b/contracts/interfaces/IStrategyV3.sol @@ -19,9 +19,7 @@ interface IStrategyV3 is IStrategyV2 { /// @dev {DEFAULT_PERFORMANCE_FEE} by default, FEE_DENOMINATOR is used uint performanceFee; - /// @notice Ratio to split performance fee on toPerf + toInsurance, [0..100_000] - /// 100_000 - send full amount toPerf, 0 - send full amount toInsurance. - uint performanceFeeRatio; + uint __deprecated; /// @dev Percent of profit for autocompound inside this strategy. uint compoundRatio; diff --git a/contracts/interfaces/IVaultInsurance.sol b/contracts/interfaces/IVaultInsurance.sol deleted file mode 100644 index d191cd1..0000000 --- a/contracts/interfaces/IVaultInsurance.sol +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity 0.8.17; - -interface IVaultInsurance { - - function init(address _vault, address _asset) external; - - function vault() external view returns (address); - - function asset() external view returns (address); - - function transferToVault(uint amount) external; - -} diff --git a/contracts/lib/InterfaceIds.sol b/contracts/lib/InterfaceIds.sol index 423da7e..6ce8fe5 100644 --- a/contracts/lib/InterfaceIds.sol +++ b/contracts/lib/InterfaceIds.sol @@ -33,7 +33,6 @@ library InterfaceIds { bytes4 public constant I_PLATFORM_VOTER = bytes4(keccak256("IPlatformVoter")); bytes4 public constant I_VE_DISTRIBUTOR = bytes4(keccak256("IVeDistributor")); bytes4 public constant I_TETU_CONVERTER = bytes4(keccak256("ITetuConverter")); - bytes4 public constant I_VAULT_INSURANCE = bytes4(keccak256("IVaultInsurance")); bytes4 public constant I_STRATEGY_STRICT = bytes4(keccak256("IStrategyStrict")); bytes4 public constant I_ERC4626 = bytes4(keccak256("IERC4626")); diff --git a/contracts/strategy/StrategyBaseV3.sol b/contracts/strategy/StrategyBaseV3.sol index 93abf43..b8fea43 100644 --- a/contracts/strategy/StrategyBaseV3.sol +++ b/contracts/strategy/StrategyBaseV3.sol @@ -75,10 +75,6 @@ abstract contract StrategyBaseV3 is IStrategyV3, ControllableV3 { return baseState.performanceFee; } - function performanceFeeRatio() external view returns (uint) { - return baseState.performanceFeeRatio; - } - function strategySpecificName() external view returns (string memory) { return baseState.strategySpecificName; } @@ -122,8 +118,8 @@ abstract contract StrategyBaseV3 is IStrategyV3, ControllableV3 { // ************************************************************* /// @notice Set performance fee, receiver and ratio - function setupPerformanceFee(uint fee_, address receiver_, uint ratio_) external { - StrategyLib2.setupPerformanceFee(baseState, fee_, receiver_, ratio_, controller()); + function setupPerformanceFee(uint fee_, address receiver_) external { + StrategyLib2.setupPerformanceFee(baseState, fee_, receiver_, controller()); } // ************************************************************* diff --git a/contracts/strategy/StrategyLib2.sol b/contracts/strategy/StrategyLib2.sol index a336381..ef062d9 100644 --- a/contracts/strategy/StrategyLib2.sol +++ b/contracts/strategy/StrategyLib2.sol @@ -43,7 +43,7 @@ library StrategyLib2 { event InvestAll(uint balance); event WithdrawAllToSplitter(uint amount); event WithdrawToSplitter(uint amount, uint sent, uint balance); - event PerformanceFeeChanged(uint fee, address receiver, uint ratio); + event PerformanceFeeChanged(uint fee, address receiver); // ************************************************************* // CHECKS AND EMITS @@ -60,12 +60,11 @@ library StrategyLib2 { emit InvestAll(assetBalance); } - function _checkSetupPerformanceFee(address controller, uint fee_, address receiver_, uint ratio_) internal { + function _checkSetupPerformanceFee(address controller, uint fee_, address receiver_) internal { onlyGovernance(controller); require(fee_ <= DENOMINATOR, TOO_HIGH); require(receiver_ != address(0), WRONG_VALUE); - require(ratio_ <= DENOMINATOR, TOO_HIGH); - emit PerformanceFeeChanged(fee_, receiver_, ratio_); + emit PerformanceFeeChanged(fee_, receiver_); } // ************************************************************* @@ -128,11 +127,10 @@ library StrategyLib2 { require(IControllable(splitter_).isController(controller_), WRONG_VALUE); } - function setupPerformanceFee(IStrategyV3.BaseState storage baseState, uint fee_, address receiver_, uint ratio_, address controller_) external { - _checkSetupPerformanceFee(controller_, fee_, receiver_, ratio_); + function setupPerformanceFee(IStrategyV3.BaseState storage baseState, uint fee_, address receiver_, address controller_) external { + _checkSetupPerformanceFee(controller_, fee_, receiver_); baseState.performanceFee = fee_; baseState.performanceReceiver = receiver_; - baseState.performanceFeeRatio = ratio_; } /// @notice Calculate withdrawn amount in USD using the {assetPrice}. diff --git a/contracts/vault/StrategySplitterV2.sol b/contracts/vault/StrategySplitterV2.sol index b2d2f62..a4252a5 100644 --- a/contracts/vault/StrategySplitterV2.sol +++ b/contracts/vault/StrategySplitterV2.sol @@ -311,7 +311,6 @@ contract StrategySplitterV2 is ControllableV3, ReentrancyGuard, ISplitter { delete isValidStrategy[strategy]; // for expensive strategies should be called before removing - // without loss covering IStrategyV2(strategy).withdrawAllToSplitter(); emit StrategyRemoved(strategy); } @@ -558,7 +557,7 @@ contract StrategySplitterV2 is ControllableV3, ReentrancyGuard, ISplitter { /// @dev Register profit/loss data for the strategy. /// Sender assume to be a registered strategy. - /// Suppose to be used in actions where we updated assets price and need to cover the price diff gap. + /// Suppose to be used in actions where we updated assets price and need to check the price diff gap. function registerStrategyLoss(uint earned, uint lost) external override { address strategy = msg.sender; require(isValidStrategy[strategy], "SS: Invalid strategy"); @@ -651,9 +650,9 @@ contract StrategySplitterV2 is ControllableV3, ReentrancyGuard, ISplitter { ) internal returns (uint apr, uint avgApr) { apr = 0; avgApr = 0; - uint lostForCovering = lost > earned ? lost - earned : 0; - if (lostForCovering > 0) { - _checkLoss(lostForCovering, HARDWORK_LOSS_TOLERANCE, strategyTvl); + uint lostForCheck = lost > earned ? lost - earned : 0; + if (lostForCheck > 0) { + _checkLoss(lostForCheck, HARDWORK_LOSS_TOLERANCE, strategyTvl); } if (registerApr) { diff --git a/contracts/vault/VaultFactory.sol b/contracts/vault/VaultFactory.sol index 3b7792a..f287f07 100644 --- a/contracts/vault/VaultFactory.sol +++ b/contracts/vault/VaultFactory.sol @@ -8,11 +8,11 @@ import "../interfaces/IERC20.sol"; import "../interfaces/ITetuVaultV2.sol"; import "../interfaces/ISplitter.sol"; import "../proxy/ProxyControlled.sol"; -import "./VaultInsurance.sol"; import "../lib/InterfaceIds.sol"; /// @title Factory for vaults. /// @author belbix +/// @author a17 contract VaultFactory is TetuERC165 { // ************************************************************* @@ -31,8 +31,7 @@ contract VaultFactory is TetuERC165 { /// @dev TetuVaultV2 contract address address public vaultImpl; - /// @dev VaultInsurance contract address - address public vaultInsuranceImpl; + /// @dev StrategySplitterV2 contract address address public splitterImpl; @@ -56,23 +55,19 @@ contract VaultFactory is TetuERC165 { address splitterLogic ); event VaultImplChanged(address value); - event VaultInsuranceImplChanged(address value); event SplitterImplChanged(address value); constructor( address _controller, address _vaultImpl, - address _vaultInsuranceImpl, address _splitterImpl ) { _requireInterface(_controller, InterfaceIds.I_CONTROLLER); _requireInterface(_vaultImpl, InterfaceIds.I_TETU_VAULT_V2); - _requireInterface(_vaultInsuranceImpl, InterfaceIds.I_VAULT_INSURANCE); _requireInterface(_splitterImpl, InterfaceIds.I_SPLITTER); controller = _controller; vaultImpl = _vaultImpl; - vaultInsuranceImpl = _vaultInsuranceImpl; splitterImpl = _splitterImpl; } @@ -107,13 +102,6 @@ contract VaultFactory is TetuERC165 { emit VaultImplChanged(value); } - /// @dev Set VaultInsurance contract address - function setVaultInsuranceImpl(address value) external onlyGov { - _requireInterface(value, InterfaceIds.I_VAULT_INSURANCE); - vaultInsuranceImpl = value; - emit VaultInsuranceImplChanged(value); - } - /// @dev Set StrategySplitterV2 contract address function setSplitterImpl(address value) external onlyGov { _requireInterface(value, InterfaceIds.I_SPLITTER); diff --git a/contracts/vault/VaultInsurance.sol b/contracts/vault/VaultInsurance.sol deleted file mode 100644 index 820c69e..0000000 --- a/contracts/vault/VaultInsurance.sol +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: BUSL-1.1 - -pragma solidity 0.8.17; - -import "../openzeppelin/SafeERC20.sol"; -import "../tools/TetuERC165.sol"; -import "../interfaces/IERC20.sol"; -import "../interfaces/IVaultInsurance.sol"; -import "../interfaces/ITetuVaultV2.sol"; -import "../lib/InterfaceIds.sol"; - -/// @title Simple dedicated contract for store vault fees -/// @author belbix -contract VaultInsurance is TetuERC165, IVaultInsurance { - using SafeERC20 for IERC20; - - /// @dev Vault address - address public override vault; - /// @dev Vault underlying asset - address public override asset; - - /// @dev Init contract with given attributes. - /// Should be called from factory during creation process. - function init(address _vault, address _asset) external override { - require(vault == address(0) && asset == address(0), "INITED"); - _requireInterface(_vault, InterfaceIds.I_TETU_VAULT_V2); - _requireERC20(_asset); - - vault = _vault; - asset = _asset; - } - - /// @dev Transfer tokens to vault in case of covering need. - function transferToVault(uint amount) external override { - require(msg.sender == vault, "!VAULT"); - IERC20(asset).safeTransfer(msg.sender, amount); - } - - /// @dev See {IERC165-supportsInterface}. - function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { - return interfaceId == InterfaceIds.I_VAULT_INSURANCE || super.supportsInterface(interfaceId); - } - -} diff --git a/test/vault/SplitterForBaseStrategyV3Tests.ts b/test/vault/SplitterForBaseStrategyV3Tests.ts index f76dc2d..224feae 100644 --- a/test/vault/SplitterForBaseStrategyV3Tests.ts +++ b/test/vault/SplitterForBaseStrategyV3Tests.ts @@ -595,7 +595,7 @@ describe("SplitterForBaseStrategyV3Tests", function () { expect(await splitter.strategyAPRHistoryLength(strategy2.address)).eq(4); }); - it("deposit with huge loss without covering", async () => { + it("deposit with huge loss", async () => { expect(await vault.sharePrice()).eq(1000000); await strategy2.setSlippageDeposit(100); await vault.deposit(1000_000, signer.address); @@ -603,7 +603,7 @@ describe("SplitterForBaseStrategyV3Tests", function () { expect(await vault.sharePrice()).eq(999500); }); - it("deposit with loss without covering", async () => { + it("deposit with loss", async () => { expect(await vault.sharePrice()).eq(1000000); await strategy2.setSlippageDeposit(100); await vault.deposit(1000_000, signer.address); @@ -611,7 +611,7 @@ describe("SplitterForBaseStrategyV3Tests", function () { expect(await vault.totalAssets()).eq(1999000); }); - it("hardwork with loss without covering", async () => { + it("hardwork with loss", async () => { expect(await vault.sharePrice()).eq(1000000); await strategy2.setSlippageHardWork(30); await vault.deposit(1000_000, signer.address); @@ -620,7 +620,7 @@ describe("SplitterForBaseStrategyV3Tests", function () { expect(await vault.totalAssets()).eq(1999400); }); - it("hardwork with loss without covering", async () => { + it("hardwork with loss", async () => { expect(await vault.sharePrice()).eq(1000000); await strategy2.setSlippageHardWork(30); await vault.deposit(1000_000, signer.address); @@ -629,7 +629,7 @@ describe("SplitterForBaseStrategyV3Tests", function () { expect(await vault.totalAssets()).eq(1999400); }); - it("rebalance with loss without covering", async () => { + it("rebalance with loss", async () => { expect(await vault.sharePrice()).eq(1000000); await splitter.setAPRs([strategy.address], [200]); @@ -643,7 +643,7 @@ describe("SplitterForBaseStrategyV3Tests", function () { expect(await vault.totalAssets()).eq(1000750); }); - it("rebalance with loss WITHOUT covering", async () => { + it("rebalance with loss", async () => { expect(await vault.sharePrice()).eq(1000000); await splitter.setAPRs([strategy.address], [200]); @@ -756,107 +756,44 @@ describe("SplitterForBaseStrategyV3Tests", function () { describe("with totalAssetsDelta != 0", async () => { describe("investAll", () => { - it("should cover expected loss if totalAssets-after is less than totalAssets-before", async () => { - // const insurance = await vault.insurance(); + it("totalAssets-after is less than totalAssets-before", async () => { await splitter.addStrategies([strategy.address], [100], [0]); - - // await usdc.mint(insurance, 500_000); - // const insuranceBefore = await usdc.balanceOf(insurance); await strategy.setSlippageDeposit(100); await vault.deposit(1000_000, signer.address); - // const insuranceAfter = await usdc.balanceOf(insurance); - - // expect(insuranceAfter).eq(insuranceBefore.sub(1000)); }); - it("should not use insurance if totalAssets-after is greater than totalAssets-before", async () => { - // const insurance = await vault.insurance(); + it("totalAssets-after is greater than totalAssets-before", async () => { await splitter.addStrategies([strategy.address], [100], [0]); - - // await usdc.mint(insurance, 500); - // const insuranceBefore = await usdc.balanceOf(insurance); await strategy.setTotalAssetsDelta(-30); await vault.deposit(1000, signer.address); - // const insuranceAfter = await usdc.balanceOf(insurance); - - // expect(insuranceAfter.eq(insuranceBefore)).eq(true); }); }); describe("withdrawToVault", () => { - it.skip("should cover expected loss if totalAssets-after is less than totalAssets-before", async () => { - // const insurance = await vault.insurance(); - await splitter.addStrategies([strategy.address], [100], [0]); - - // await usdc.mint(insurance, 50000); - await vault.deposit(100000, signer.address); - // await vault.setFees(0, 200) - - // const insuranceBefore = await usdc.balanceOf(insurance); - await strategy.setSlippage(100); - await vault.withdraw(50000, signer.address, signer.address); - // const insuranceAfter = await usdc.balanceOf(insurance); - - // expect(insuranceAfter).eq(49950); - }); - /*it("should not use ance if totalAssets-after is greater than totalAssets-before", async () => { - const insurance = await vault.insurance(); + it("totalAssets-after is greater than totalAssets-before", async () => { await splitter.addStrategies([strategy.address], [100], [0]); - await usdc.mint(insurance, 5000); await vault.deposit(10000, signer.address); - const insuranceBefore = await usdc.balanceOf(insurance); await strategy.setTotalAssetsDelta(-30); await vault.withdraw(500, signer.address, signer.address); - const insuranceAfter = await usdc.balanceOf(insurance); - - expect(insuranceAfter.eq(insuranceBefore)).eq(true); - });*/ + }); }); describe("withdrawAll", () => { - it("should cover expected loss if totalAssets-after is less than totalAssets-before", async () => { - // const insurance = await vault.insurance(); + it("totalAssets-after is less than totalAssets-before", async () => { await splitter.addStrategies([strategy.address], [100], [0]); - - // await usdc.mint(insurance, 5000_000); await vault.deposit(10_000_000, signer.address); await vault.connect(await Misc.impersonate('0xdEad000000000000000000000000000000000000')).transfer(signer.address, await vault.balanceOf('0xdEad000000000000000000000000000000000000')); - - // const insuranceBefore = await usdc.balanceOf(insurance); await strategy.setSlippage(100); await vault.withdrawAll(); - // const insuranceAfter = await usdc.balanceOf(insurance); - - // console.log("insuranceBefore", insuranceBefore); - // console.log("insuranceAfter", insuranceAfter); - // expect(insuranceAfter).eq(insuranceBefore.sub(10000)); }); - // it("should not use insurance if totalAssets-after is greater than totalAssets-before", async () => { - // const insurance = await vault.insurance(); - // await splitter.addStrategies([strategy.address], [100]); - // - // await usdc.mint(insurance, 5000); - // await vault.deposit(10000, signer.address); - // - // const insuranceBefore = await usdc.balanceOf(insurance); - // await strategy.setSlippage(10_000); - // await vault.withdrawAll(); - // const insuranceAfter = await usdc.balanceOf(insurance); - // - // expect(insuranceAfter).eq(insuranceBefore); - // }); }); }); }); 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); await splitter.addStrategies([strategy.address], [100], [0]); - const sharePriceBefore = await vault.sharePrice(); expect(sharePriceBefore).eq(1_000_000); - expect(await vault.totalSupply()).eq(0) await vault.deposit(1000_000, signer.address); expect(await vault.totalSupply()).eq(1000_000) @@ -865,27 +802,15 @@ describe("SplitterForBaseStrategyV3Tests", function () { expect(await strategy.investedAssets()).eq(1000_000) expect(await usdc.balanceOf(strategy.address)).eq(0) expect(await usdc.balanceOf(splitter.address)).eq(0) - expect(sharePriceBefore).eq(await vault.sharePrice()); - - // const insuranceBefore = await usdc.balanceOf(insurance); - // console.log('insuranceBefore', insuranceBefore) - await strategy.setUseTrueExpectedWithdraw(true) await strategy.setSlippage(1_000); - await expect(vault.withdrawAll()).revertedWith('SB: Too high') - - // const insuranceAfter = await usdc.balanceOf(insurance); - // console.log('insuranceAfter', insuranceAfter) - // expect(insuranceAfter).eq(0); - expect(sharePriceBefore).eq(await vault.sharePrice()); }); it("should register loss with registerStrategyLoss call", async () => { await strategy.init(controller.address, splitter.address); - // await vault.setFees(300, 300); // console.log('add strategy') await splitter.addStrategies([strategy.address], [100], [0]); diff --git a/test/vault/SplitterTests.ts b/test/vault/SplitterTests.ts index 68f5032..67b144e 100644 --- a/test/vault/SplitterTests.ts +++ b/test/vault/SplitterTests.ts @@ -11,7 +11,6 @@ import { MockGauge__factory, MockStrategy, MockStrategy__factory, - MockStrategySimple, MockStrategySimple__factory, MockToken, StrategySplitterV2, @@ -600,7 +599,7 @@ describe("SplitterTests", function () { expect(await splitter.strategyAPRHistoryLength(strategy2.address)).eq(4); }); - it("deposit with huge loss without covering", async () => { + it("deposit with huge loss", async () => { expect(await vault.sharePrice()).eq(1000000); await strategy2.setSlippageDeposit(100); await vault.deposit(1000_000, signer.address); @@ -608,7 +607,7 @@ describe("SplitterTests", function () { expect(await vault.sharePrice()).eq(999500); }); - it("deposit with loss without covering", async () => { + it("deposit with loss", async () => { expect(await vault.sharePrice()).eq(1000000); await strategy2.setSlippageDeposit(100); await vault.deposit(1000_000, signer.address); @@ -616,7 +615,7 @@ describe("SplitterTests", function () { expect(await vault.totalAssets()).eq(1999000); }); - it("hardwork with loss without covering", async () => { + it("hardwork with loss", async () => { expect(await vault.sharePrice()).eq(1000000); await strategy2.setSlippageHardWork(30); await vault.deposit(1000_000, signer.address); @@ -625,7 +624,7 @@ describe("SplitterTests", function () { expect(await vault.totalAssets()).eq(1999400); }); - it("hardwork with loss without covering", async () => { + it("hardwork with loss", async () => { expect(await vault.sharePrice()).eq(1000000); await strategy2.setSlippageHardWork(30); await vault.deposit(1000_000, signer.address); @@ -634,7 +633,7 @@ describe("SplitterTests", function () { expect(await vault.totalAssets()).eq(1999400); }); - it("rebalance with loss without covering", async () => { + it("rebalance with loss", async () => { expect(await vault.sharePrice()).eq(1000000); await splitter.setAPRs([strategy.address], [200]); @@ -648,7 +647,7 @@ describe("SplitterTests", function () { expect(await vault.totalAssets()).eq(1000750); }); - it("rebalance with loss WITHOUT covering", async () => { + it("rebalance with loss", async () => { expect(await vault.sharePrice()).eq(1000000); await splitter.setAPRs([strategy.address], [200]); @@ -760,101 +759,33 @@ describe("SplitterTests", function () { describe("with totalAssetsDelta != 0", async () => { describe("investAll", () => { - it("should cover expected loss if totalAssets-after is less than totalAssets-before", async () => { - // const insurance = await vault.insurance(); + it("totalAssets-after is less than totalAssets-before", async () => { await splitter.addStrategies([strategy.address], [100], [0]); - - // await usdc.mint(insurance, 500_000); - // const insuranceBefore = await usdc.balanceOf(insurance); await strategy.setSlippageDeposit(100); await vault.deposit(1000_000, signer.address); - // const insuranceAfter = await usdc.balanceOf(insurance); - - // expect(insuranceAfter).eq(insuranceBefore.sub(1000)); }); - /*it("should not use insurance if totalAssets-after is greater than totalAssets-before", async () => { - const insurance = await vault.insurance(); - await splitter.addStrategies([strategy.address], [100], [0]); - - await usdc.mint(insurance, 500); - const insuranceBefore = await usdc.balanceOf(insurance); - await strategy.setTotalAssetsDelta(-30); - await vault.deposit(1000, signer.address); - const insuranceAfter = await usdc.balanceOf(insurance); - - expect(insuranceAfter.eq(insuranceBefore)).eq(true); - });*/ }); describe("withdrawToVault", () => { - it.skip("should cover expected loss if totalAssets-after is less than totalAssets-before", async () => { - // const insurance = await vault.insurance(); - await splitter.addStrategies([strategy.address], [100], [0]); - - // await usdc.mint(insurance, 50000); - await vault.deposit(100000, signer.address); - // await vault.setFees(0, 200) - - // const insuranceBefore = await usdc.balanceOf(insurance); - await strategy.setSlippage(100); - await vault.withdraw(50000, signer.address, signer.address); - // const insuranceAfter = await usdc.balanceOf(insurance); - - // expect(insuranceAfter).eq(49950); - }); - /*it("should not use insurance if totalAssets-after is greater than totalAssets-before", async () => { - const insurance = await vault.insurance(); + it("totalAssets-after is greater than totalAssets-before", async () => { await splitter.addStrategies([strategy.address], [100], [0]); - - await usdc.mint(insurance, 5000); await vault.deposit(10000, signer.address); - - const insuranceBefore = await usdc.balanceOf(insurance); await strategy.setTotalAssetsDelta(-30); await vault.withdraw(500, signer.address, signer.address); - const insuranceAfter = await usdc.balanceOf(insurance); - - expect(insuranceAfter.eq(insuranceBefore)).eq(true); - });*/ + }); }); describe("withdrawAll", () => { - it("should cover expected loss if totalAssets-after is less than totalAssets-before", async () => { - // const insurance = await vault.insurance(); + it("totalAssets-after is less than totalAssets-before", async () => { await splitter.addStrategies([strategy.address], [100], [0]); - - // await usdc.mint(insurance, 5000_000); await vault.deposit(10_000_000, signer.address); await vault.connect(await Misc.impersonate('0xdEad000000000000000000000000000000000000')).transfer(signer.address, await vault.balanceOf('0xdEad000000000000000000000000000000000000')); - - // const insuranceBefore = await usdc.balanceOf(insurance); await strategy.setSlippage(100); await vault.withdrawAll(); - // const insuranceAfter = await usdc.balanceOf(insurance); - - // console.log("insuranceBefore", insuranceBefore); - // console.log("insuranceAfter", insuranceAfter); - // expect(insuranceAfter).eq(insuranceBefore.sub(10000)); }); - // it("should not use insurance if totalAssets-after is greater than totalAssets-before", async () => { - // const insurance = await vault.insurance(); - // await splitter.addStrategies([strategy.address], [100]); - // - // await usdc.mint(insurance, 5000); - // await vault.deposit(10000, signer.address); - // - // const insuranceBefore = await usdc.balanceOf(insurance); - // await strategy.setSlippage(10_000); - // await vault.withdrawAll(); - // const insuranceAfter = await usdc.balanceOf(insurance); - // - // expect(insuranceAfter).eq(insuranceBefore); - // }); }); }); }); it("should not change share price", async () => { - // const insurance = await vault.insurance(); - await strategy.init(controller.address, splitter.address); await splitter.addStrategies([strategy.address], [100], [0]); @@ -872,25 +803,16 @@ describe("SplitterTests", function () { expect(sharePriceBefore).eq(await vault.sharePrice()); - // const insuranceBefore = await usdc.balanceOf(insurance); - // console.log('insuranceBefore', insuranceBefore) - await strategy.setUseTrueExpectedWithdraw(true) await strategy.setSlippage(10); - // await vault.setFees(0, 1000) await vault.withdrawAll(); - // const insuranceAfter = await usdc.balanceOf(insurance); - // console.log('insuranceAfter', insuranceAfter) - // expect(insuranceAfter).eq(0); - expect(sharePriceBefore).eq(await vault.sharePrice()); }); - it("should register loss with coverPossibleStrategyLoss call", async () => { + it("should register loss with registerStrategyLoss call", async () => { await strategy.init(controller.address, splitter.address); - // await vault.setFees(300, 300); // console.log('add strategy') await splitter.addStrategies([strategy.address], [100], [0]); diff --git a/test/vault/StrategyBaseV3Tests.ts b/test/vault/StrategyBaseV3Tests.ts index c836ddb..cb0fd7f 100644 --- a/test/vault/StrategyBaseV3Tests.ts +++ b/test/vault/StrategyBaseV3Tests.ts @@ -107,14 +107,13 @@ describe("StrategyBaseV3Tests", function () { it("should return expected fee, receiver and ratio", async () => { const governance = await IController__factory.connect(await strategyAsSplitter.controller(), signer).governance(); const receiver = ethers.Wallet.createRandom(); - await strategyAsSplitter.connect(await Misc.impersonate(governance)).setupPerformanceFee(5_000, receiver.address, 2); + await strategyAsSplitter.connect(await Misc.impersonate(governance)).setupPerformanceFee(5_000, receiver.address); const ret = [ await strategyAsSplitter.performanceFee(), await strategyAsSplitter.performanceReceiver(), - await strategyAsSplitter.performanceFeeRatio(), ].join(); - const expected = [5_000, receiver.address, 2].join(); + const expected = [5_000, receiver.address].join(); expect(ret).eq(expected); }); }); @@ -123,29 +122,22 @@ describe("StrategyBaseV3Tests", function () { const receiver = ethers.Wallet.createRandom(); const notGovernance = ethers.Wallet.createRandom().address; await expect( - strategyAsSplitter.connect(await Misc.impersonate(notGovernance)).setupPerformanceFee(5_000, receiver.address, 0) + strategyAsSplitter.connect(await Misc.impersonate(notGovernance)).setupPerformanceFee(5_000, receiver.address) ).revertedWith("SB: Denied"); // DENIED }); it("should revert if the fee is too high", async () => { const governance = await IController__factory.connect(await strategyAsSplitter.controller(), signer).governance(); const receiver = ethers.Wallet.createRandom(); await expect( - strategyAsSplitter.connect(await Misc.impersonate(governance)).setupPerformanceFee(101_000, receiver.address, 0) + strategyAsSplitter.connect(await Misc.impersonate(governance)).setupPerformanceFee(101_000, receiver.address) ).revertedWith("SB: Too high"); // TOO_HIGH }); it("should revert if the receiver is zero", async () => { const governance = await IController__factory.connect(await strategyAsSplitter.controller(), signer).governance(); await expect( - strategyAsSplitter.connect(await Misc.impersonate(governance)).setupPerformanceFee(10_000, Misc.ZERO_ADDRESS, 0) + strategyAsSplitter.connect(await Misc.impersonate(governance)).setupPerformanceFee(10_000, Misc.ZERO_ADDRESS) ).revertedWith("SB: Wrong value"); // WRONG_VALUE }); - it("should revert if the ratio is too high", async () => { - const governance = await IController__factory.connect(await strategyAsSplitter.controller(), signer).governance(); - const receiver = ethers.Wallet.createRandom(); - await expect( - strategyAsSplitter.connect(await Misc.impersonate(governance)).setupPerformanceFee(10_000, receiver.address, 101_000) - ).revertedWith("SB: Too high"); // TOO_HIGH - }); }); }); //endregion Unit tests diff --git a/test/vault/TetuVaultV2Tests.ts b/test/vault/TetuVaultV2Tests.ts index b1ab914..72c405e 100644 --- a/test/vault/TetuVaultV2Tests.ts +++ b/test/vault/TetuVaultV2Tests.ts @@ -324,16 +324,6 @@ describe("Tetu Vault V2 tests", function () { await expect(vault.connect(signer2).setDoHardWorkOnInvest(false)).revertedWith("DENIED"); }); - /*it("insurance transfer revert", async () => { - const insurance = VaultInsurance__factory.connect(await vault.insurance(), signer); - await expect(insurance.init(Misc.ZERO_ADDRESS, Misc.ZERO_ADDRESS)).revertedWith("INITED"); - });*/ - - /*it("insurance transfer revert", async () => { - const insurance = VaultInsurance__factory.connect(await vault.insurance(), signer); - await expect(insurance.transferToVault(1)).revertedWith("!VAULT"); - });*/ - it("set DoHardWorkOnInvest test", async () => { await vault.setDoHardWorkOnInvest(false); expect(await vault.doHardWorkOnInvest()).eq(false); diff --git a/test/vault/VaultFactoryTests.ts b/test/vault/VaultFactoryTests.ts index 419c227..9aef297 100644 --- a/test/vault/VaultFactoryTests.ts +++ b/test/vault/VaultFactoryTests.ts @@ -23,7 +23,6 @@ describe("Vault factory tests", function () { let snapshotBefore: string; let snapshot: string; let signer: SignerWithAddress; - let signer1: SignerWithAddress; let signer2: SignerWithAddress; let controller: ControllerMinimal; let usdc: MockToken; @@ -32,18 +31,17 @@ describe("Vault factory tests", function () { before(async function () { - [signer, signer1, signer2] = await ethers.getSigners() + [signer, signer2] = await ethers.getSigners() snapshotBefore = await TimeUtils.snapshot(); controller = await DeployerUtils.deployMockController(signer); usdc = await DeployerUtils.deployMockToken(signer, 'USDC', 6); const vaultLogic = await DeployerUtils.deployContract(signer, 'TetuVaultV2'); - const insurance = await DeployerUtils.deployContract(signer, 'VaultInsurance'); const splitter = await DeployerUtils.deployContract(signer, 'MockSplitter'); vaultFactory = await DeployerUtils.deployContract(signer, 'VaultFactory', controller.address, - vaultLogic.address, insurance.address, splitter.address) as VaultFactory; + vaultLogic.address, splitter.address) as VaultFactory; mockGauge = MockGauge__factory.connect(await DeployerUtils.deployProxy(signer, 'MockGauge'), signer); await mockGauge.init(controller.address) @@ -108,16 +106,6 @@ describe("Vault factory tests", function () { await expect(vaultFactory.connect(signer2).setVaultImpl(Misc.ZERO_ADDRESS)).revertedWith('!GOV'); }); - it("set insurance test", async () => { - const insurance2 = await DeployerUtils.deployContract(signer, 'VaultInsurance'); - await vaultFactory.setVaultInsuranceImpl(insurance2.address); - expect(await vaultFactory.vaultInsuranceImpl()).eq(insurance2.address); - }); - - it("set insurance revert", async () => { - await expect(vaultFactory.connect(signer2).setVaultInsuranceImpl(Misc.ZERO_ADDRESS)).revertedWith('!GOV'); - }); - it("set splitter test", async () => { const splitter2 = await DeployerUtils.deployContract(signer, 'MockSplitter'); await vaultFactory.setSplitterImpl(splitter2.address);