From 36f7dc6c281b7a9e9618d75fa92f1785c5b07a80 Mon Sep 17 00:00:00 2001 From: lsqrl Date: Mon, 15 Jan 2024 14:59:52 +0100 Subject: [PATCH] audit refix l12 --- src/Manager.sol | 8 ++++---- test/Manager.test.sol | 14 ++++++------- test/services/AaveService.economic.test.sol | 4 ++-- test/services/AaveService.general.test.sol | 4 ++-- test/services/BaseIntegrationServiceTest.sol | 4 ++-- test/services/DebitCredit.test.sol | 21 +++++++++++--------- test/services/GmxService.test.sol | 8 ++++---- test/services/SeniorCallOption.test.sol | 4 ++-- test/services/WhitelistedService.test.sol | 4 ++-- 9 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/Manager.sol b/src/Manager.sol index 845724db..0f301877 100644 --- a/src/Manager.sol +++ b/src/Manager.sol @@ -41,13 +41,13 @@ contract Manager is IManager, Ownable { abi.encodePacked(type(Vault).creationCode, abi.encode(IERC20Metadata(token))) ); vaults[token] = vault; - // deposit 1 token unit to avoid the typical ERC4626 issue + // deposit 1000 wei unit to avoid the typical ERC4626 issue // by placing the resulting iToken in the manager, it becomes unredeemable // therefore, the Vault is guaranteed to always stay in a healthy status IERC20 tkn = IERC20(token); - tkn.safeTransferFrom(msg.sender, address(this), 1); - tkn.approve(vault, 1); - IVault(vault).deposit(1, address(this)); + tkn.safeTransferFrom(msg.sender, address(this), 1000); + tkn.approve(vault, 1000); + IVault(vault).deposit(1000, address(this)); emit VaultCreated(token, vault); diff --git a/test/Manager.test.sol b/test/Manager.test.sol index 638950ea..b6b1406f 100644 --- a/test/Manager.test.sol +++ b/test/Manager.test.sol @@ -42,11 +42,11 @@ contract ManagerTest is Test { secondToken.mint(tokenSink, type(uint256).max); spuriousToken.mint(tokenSink, type(uint256).max); vm.startPrank(tokenSink); - firstToken.transfer(address(this), 1); - secondToken.transfer(address(this), 1); + firstToken.transfer(address(this), 1000); + secondToken.transfer(address(this), 1000); vm.stopPrank(); - firstToken.approve(address(manager), 1); - secondToken.approve(address(manager), 1); + firstToken.approve(address(manager), 1000); + secondToken.approve(address(manager), 1000); } function setUp() public { @@ -78,15 +78,15 @@ contract ManagerTest is Test { function testCreate() public { vm.prank(tokenSink); - spuriousToken.transfer(address(this), 1); - spuriousToken.approve(address(manager), 1); + spuriousToken.transfer(address(this), 1000); + spuriousToken.approve(address(manager), 1000); address spuriousVault = manager.create(address(spuriousToken)); assertTrue(manager.vaults(address(spuriousToken)) == spuriousVault); } function _setupArbitraryState(uint256 previousDeposit, uint256 cap) private returns (uint256) { address vaultAddress = manager.vaults(address(firstToken)); - if (previousDeposit == type(uint256).max) previousDeposit--; + if (previousDeposit >= type(uint256).max - 999) previousDeposit = type(uint256).max - 1000; vm.startPrank(tokenSink); firstToken.approve(vaultAddress, previousDeposit); IVault(vaultAddress).deposit(previousDeposit, anyAddress); diff --git a/test/services/AaveService.economic.test.sol b/test/services/AaveService.economic.test.sol index b2d2a188..4060876f 100644 --- a/test/services/AaveService.economic.test.sol +++ b/test/services/AaveService.economic.test.sol @@ -53,9 +53,9 @@ contract AaveEconomicTest is Test, IERC721Receiver { for (uint256 i = 0; i < loanLength; i++) { // Create Vault: DAI vm.prank(whales[loanTokens[i]]); - IERC20(loanTokens[i]).transfer(admin, 1); + IERC20(loanTokens[i]).transfer(admin, 1000); vm.startPrank(admin); - IERC20(loanTokens[i]).approve(address(manager), 1); + IERC20(loanTokens[i]).approve(address(manager), 1000); manager.create(loanTokens[i]); // No caps for this service -> 100% of the liquidity can be used initially manager.setCap(address(service), loanTokens[i], GeneralMath.RESOLUTION, type(uint256).max); diff --git a/test/services/AaveService.general.test.sol b/test/services/AaveService.general.test.sol index 80c0b91a..71fb657d 100644 --- a/test/services/AaveService.general.test.sol +++ b/test/services/AaveService.general.test.sol @@ -54,9 +54,9 @@ contract AaveGeneralTest is Test, IERC721Receiver { for (uint256 i = 0; i < loanLength; i++) { // Create Vault: DAI vm.prank(whales[loanTokens[i]]); - IERC20(loanTokens[i]).transfer(admin, 1); + IERC20(loanTokens[i]).transfer(admin, 1000); vm.startPrank(admin); - IERC20(loanTokens[i]).approve(address(manager), 1); + IERC20(loanTokens[i]).approve(address(manager), 1000); manager.create(loanTokens[i]); // No caps for this service -> 100% of the liquidity can be used initially manager.setCap(address(service), loanTokens[i], GeneralMath.RESOLUTION, type(uint256).max); diff --git a/test/services/BaseIntegrationServiceTest.sol b/test/services/BaseIntegrationServiceTest.sol index 865907c5..2c72ea95 100644 --- a/test/services/BaseIntegrationServiceTest.sol +++ b/test/services/BaseIntegrationServiceTest.sol @@ -46,9 +46,9 @@ contract BaseIntegrationServiceTest is Test, IERC721Receiver { for (uint256 i = 0; i < loanLength; i++) { if (manager.vaults(loanTokens[i]) == address(0)) { vm.prank(whales[loanTokens[i]]); - IERC20(loanTokens[i]).transfer(admin, 1); + IERC20(loanTokens[i]).transfer(admin, 1000); vm.startPrank(admin); - IERC20(loanTokens[i]).approve(address(manager), 1); + IERC20(loanTokens[i]).approve(address(manager), 1000); manager.create(loanTokens[i]); vm.stopPrank(); } diff --git a/test/services/DebitCredit.test.sol b/test/services/DebitCredit.test.sol index 2a57fa57..3e4aea6f 100644 --- a/test/services/DebitCredit.test.sol +++ b/test/services/DebitCredit.test.sol @@ -105,10 +105,10 @@ contract DebitCreditTest is Test, IERC721Receiver { // recall that the admin needs 1e-6 USDC to create the vault vm.stopPrank(); vm.prank(usdcWhale); - IERC20(usdc).transfer(address(admin), 1); + IERC20(usdc).transfer(address(admin), 1000); vm.startPrank(admin); - IERC20(usdc).approve(address(manager), 1); + IERC20(usdc).approve(address(manager), 1000); manager.create(usdc); // first price is 0.2 USDC: we need to double it in the constructor @@ -239,7 +239,7 @@ contract DebitCreditTest is Test, IERC721Receiver { assertLe(collaterals[1].amount, (depositedAmount * _rewards[monthsLocked]) / initialPrice); // price was bumped by at least the allocation percentage (virtually) bougth assertGe(callOptionService.currentPrice(), initialPrice); - assertEq(vault.freeLiquidity(), 4e9 + 1); + assertEq(vault.freeLiquidity(), 4e9 + 1000); // free liquidity = 4000 USDC // now depositedAmount are in the vault -> we take an Aave position @@ -250,7 +250,7 @@ contract DebitCreditTest is Test, IERC721Receiver { uint256 minCollateral = loan + margin; IERC20(usdc).approve(address(aaveService), margin); _openAavePosition(margin, loan, minCollateral); - assertEq(vault.freeLiquidity(), 3.6e9 + 1); + assertEq(vault.freeLiquidity(), 3.6e9 + 1000); vm.stopPrank(); // now, the free liquidity is 3600 USDC @@ -281,8 +281,11 @@ contract DebitCreditTest is Test, IERC721Receiver { vault.balanceOf(treasury), collaterals[0].amount - vault.convertToShares(((depositedAmount * (1e18 - calledPortion)) / 1e18)) ); - assertEq(vault.freeLiquidity(), depositedAmount - loan - (depositedAmount * (1e18 - calledPortion)) / 1e18 + 1); - assertEq(vault.freeLiquidity(), 3.2e9 + 1); + assertEq( + vault.freeLiquidity(), + depositedAmount - loan - (depositedAmount * (1e18 - calledPortion)) / 1e18 + 1000 + ); + assertEq(vault.freeLiquidity(), 3.2e9 + 1000); assertEq(vault.balanceOf(treasury), 3.6e9); vm.stopPrank(); // The free liquidity is now 3200 USDC and treasury has 3600 USDC worth of iTokens @@ -293,7 +296,7 @@ contract DebitCreditTest is Test, IERC721Receiver { monthsLocked = 7; IERC20(usdc).approve(address(callOptionService), depositedAmount); _openCallOption(depositedAmount, monthsLocked); - assertEq(vault.freeLiquidity(), 3.5e9 + 1); + assertEq(vault.freeLiquidity(), 3.5e9 + 1000); vm.stopPrank(); // Now free liquidity is 3500 USDC, and 400 are taken as loan // Total assets are 3900 USDC, so we can still take 380 USDC as loan @@ -312,7 +315,7 @@ contract DebitCreditTest is Test, IERC721Receiver { // not all liquidity can be withdrawn, let us just redeem 2900 iUSDC vault.redeem(2.9e9, treasury, treasury); // Which makes the free liquidity to be 220 USDC - assertEq(vault.freeLiquidity(), 2.2e8 + 1); + assertEq(vault.freeLiquidity(), 2.2e8 + 1000); vm.stopPrank(); vm.startPrank(callOptionSigner); @@ -342,7 +345,7 @@ contract DebitCreditTest is Test, IERC721Receiver { vm.startPrank(aaveUser); aaveService.close(0, abi.encode(0)); // it used to be 400 USDC, so now we have them back - assertEq(vault.freeLiquidity(), 6.2e8 + 1); + assertEq(vault.freeLiquidity(), 6.2e8 + 1000); vm.stopPrank(); // At this point, fees are harvested diff --git a/test/services/GmxService.test.sol b/test/services/GmxService.test.sol index 44fc02a8..046110a4 100644 --- a/test/services/GmxService.test.sol +++ b/test/services/GmxService.test.sol @@ -62,14 +62,14 @@ contract GmxServiceTest is BaseIntegrationServiceTest { usdc.approve(address(service), type(uint256).max); vm.startPrank(whale); - weth.transfer(admin, 1); + weth.transfer(admin, 1000); weth.transfer(address(mockRouter), 1e18); vm.stopPrank(); vm.prank(usdcWhale); - usdc.transfer(admin, 1); + usdc.transfer(admin, 1000); vm.startPrank(admin); - weth.approve(address(manager), 1); - usdc.approve(address(manager), 1); + weth.approve(address(manager), 1000); + usdc.approve(address(manager), 1000); manager.create(address(weth)); manager.setCap(address(service), address(weth), GeneralMath.RESOLUTION, type(uint256).max); manager.create(address(usdc)); diff --git a/test/services/SeniorCallOption.test.sol b/test/services/SeniorCallOption.test.sol index 3046af60..99141600 100644 --- a/test/services/SeniorCallOption.test.sol +++ b/test/services/SeniorCallOption.test.sol @@ -50,10 +50,10 @@ contract CallOptionTest is BaseIntegrationServiceTest { vm.stopPrank(); vm.prank(whales[loanTokens[0]]); - IERC20(loanTokens[0]).transfer(admin, 1); + IERC20(loanTokens[0]).transfer(admin, 1000); vm.startPrank(admin); - IERC20(loanTokens[0]).approve(address(manager), 1); + IERC20(loanTokens[0]).approve(address(manager), 1000); manager.create(loanTokens[0]); service = new CallOption(address(manager), address(ithil), 4e17, 1, 86400 * 30, 86400 * 30, 0, loanTokens[0]); diff --git a/test/services/WhitelistedService.test.sol b/test/services/WhitelistedService.test.sol index ce1ee0cd..85196169 100644 --- a/test/services/WhitelistedService.test.sol +++ b/test/services/WhitelistedService.test.sol @@ -56,9 +56,9 @@ contract WhitelistedTest is Test, IERC721Receiver { token.approve(address(service), type(uint256).max); vm.prank(whitelistedUser); - token.transfer(admin, 1); + token.transfer(admin, 1000); vm.startPrank(admin); - token.approve(address(manager), 1); + token.approve(address(manager), 1000); manager.create(address(token)); manager.setCap(address(service), address(token), GeneralMath.RESOLUTION, type(uint256).max); vm.stopPrank();