From 3d7474ea2798a9ccd09361605e00d130376e280b Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Thu, 21 Sep 2023 18:58:32 -0500 Subject: [PATCH] chore: cleanup --- src/zkbob/ZkBobCompoundingMixin.sol | 14 +++++--------- src/zkbob/ZkBobPool.sol | 23 +++++++++++------------ test/zkbob/ZkBobPool.t.sol | 26 +++++++++----------------- 3 files changed, 25 insertions(+), 38 deletions(-) diff --git a/src/zkbob/ZkBobCompoundingMixin.sol b/src/zkbob/ZkBobCompoundingMixin.sol index d5bf419..a2f8f2a 100644 --- a/src/zkbob/ZkBobCompoundingMixin.sol +++ b/src/zkbob/ZkBobCompoundingMixin.sol @@ -2,6 +2,7 @@ pragma solidity 0.8.15; +import "@openzeppelin/contracts/interfaces/IERC4626.sol"; import "./ZkBobPool.sol"; /** @@ -63,11 +64,11 @@ abstract contract ZkBobCompoundingMixin is ZkBobPool { address yieldAddress = yieldParams.yield; require( _yieldParams.yield == yieldAddress || investedAssetsAmount == 0, - "ZkBobCompoundingPool: Invested amount should be 0 in case of changing yield" + "ZkBobCompounding: another yield is active" ); require( _yieldParams.yield == address(0) || _yieldParams.interestReceiver != address(0), - "ZkBobCompoundingPool: interest receiver should not be address(0) for existed yield" + "ZkBobCompounding: zero interest receiver" ); if (_yieldParams.yield != yieldAddress) { @@ -110,10 +111,7 @@ abstract contract ZkBobCompoundingMixin is ZkBobPool { return; } - require( - operator == address(0) || operator == msg.sender, - "ZkBobCompoundingPool: Rebalance is an operator-called method" - ); + require(operator == address(0) || operator == msg.sender, "ZkBobCompounding: not authorized"); uint256 underlyingBalance = IERC20(token).balanceOf(address(this)); uint256 vaultAssets = investedAssetsAmount; @@ -161,9 +159,7 @@ abstract contract ZkBobCompoundingMixin is ZkBobPool { if (yieldAddress == address(0)) { return 0; } - require( - operator == address(0) || operator == msg.sender, "ZkBobCompoundingPool: Claim is an operator-called method" - ); + require(operator == address(0) || operator == msg.sender, "ZkBobCompounding: not authorized"); minClaimAmount = minClaimAmount > dust ? minClaimAmount : dust; diff --git a/src/zkbob/ZkBobPool.sol b/src/zkbob/ZkBobPool.sol index 23b95ab..14e88c6 100644 --- a/src/zkbob/ZkBobPool.sol +++ b/src/zkbob/ZkBobPool.sol @@ -3,7 +3,6 @@ pragma solidity 0.8.15; import "@openzeppelin/contracts/utils/Address.sol"; -import "@openzeppelin/contracts/interfaces/IERC4626.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; @@ -140,17 +139,6 @@ abstract contract ZkBobPool is IZkBobPool, EIP1967Admin, Ownable, Parameters, Ex emit UpdateOperatorManager(address(_operatorManager)); } - /** - * @dev Updates used energy redemption module. - * Callable only by the contract owner / proxy admin. - * @param _redeemer new energy redeemer implementation. - */ - function setEnergyRedeemer(IEnergyRedeemer _redeemer) external onlyOwner { - require(address(_redeemer) == address(0) || Address.isContract(address(_redeemer)), "ZkBobPool: not a contract"); - redeemer = _redeemer; - emit UpdateRedeemer(address(_redeemer)); - } - /** * @dev Tells the denominator for converting pool token into zkBOB units. */ @@ -171,6 +159,17 @@ abstract contract ZkBobPool is IZkBobPool, EIP1967Admin, Ownable, Parameters, Ex emit UpdateAccounting(address(_accounting)); } + /** + * @dev Updates used energy redemption module. + * Callable only by the contract owner / proxy admin. + * @param _redeemer new energy redeemer implementation. + */ + function setEnergyRedeemer(IEnergyRedeemer _redeemer) external onlyOwner { + require(address(_redeemer) == address(0) || Address.isContract(address(_redeemer)), "ZkBobPool: not a contract"); + redeemer = _redeemer; + emit UpdateRedeemer(address(_redeemer)); + } + function _root() internal view override returns (uint256) { return roots[_transfer_index()]; } diff --git a/test/zkbob/ZkBobPool.t.sol b/test/zkbob/ZkBobPool.t.sol index 69b976b..b62e0ec 100644 --- a/test/zkbob/ZkBobPool.t.sol +++ b/test/zkbob/ZkBobPool.t.sol @@ -6,8 +6,6 @@ import "forge-std/Test.sol"; import "@openzeppelin/contracts/mocks/ERC20Mock.sol"; import {ERC4626Mock} from "@openzeppelin/contracts/mocks/ERC4626Mock.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import {TransparentUpgradeableProxy as TUP} from - "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; import "@openzeppelin/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol"; import "@uniswap/v3-periphery/contracts/interfaces/INonfungiblePositionManager.sol"; import "@uniswap/v3-core/contracts/libraries/TickMath.sol"; @@ -165,17 +163,11 @@ abstract contract AbstractZkBobPoolTest is AbstractForkTest { if (isCompounding) { ATokenVault yieldVault = new ATokenVault(token, 4546, IPoolAddressesProvider(poolAddressesProvider)); deal(token, address(this), 1_000_000 ether / D); - address yieldProxyAddr = computeCreateAddress(address(this), vm.getNonce(address(this))); - IERC20(token).approve(yieldProxyAddr, type(uint256).max); - bytes memory initData = abi.encodeWithSelector( - ATokenVault.initialize.selector, - address(this), - 0.2 ether, // 20% - "Wrapped BOB Yield Token", - "wBYT", - 1_000_000 ether / D + EIP1967Proxy yieldProxy = new EIP1967Proxy(user2, address(yieldVault), ""); + IERC20(token).approve(address(yieldProxy), type(uint256).max); + ATokenVault(address(yieldProxy)).initialize( + address(this), 0.2 ether, "AAVE Vault", "AAVE", 1_000_000 ether / D ); - TUP yieldProxy = new TUP(address(yieldVault), user2, initData); pool.updateYieldParams( IZkBobPoolAdmin.YieldParams({ yield: address(yieldProxy), @@ -896,7 +888,7 @@ abstract contract AbstractZkBobPoolTest is AbstractForkTest { ); vm.prank(user2); - vm.expectRevert("ZkBobCompoundingPool: Rebalance is an operator-called method"); + vm.expectRevert("ZkBobCompounding: not authorized"); pool.rebalance(3_000 ether / D, 4_000 ether / D); } @@ -942,7 +934,7 @@ abstract contract AbstractZkBobPoolTest is AbstractForkTest { interestReceiver: address(this), yieldOperator: address(this) }); - vm.expectRevert("ZkBobCompoundingPool: Invested amount should be 0 in case of changing yield"); + vm.expectRevert("ZkBobCompounding: another yield is active"); pool.updateYieldParams(yieldParams); bytes memory data2 = _encodeWithdrawal(user1, (10_000 ether - 0.01 ether) / D, 0, 0); @@ -973,7 +965,7 @@ abstract contract AbstractZkBobPoolTest is AbstractForkTest { interestReceiver: address(0), yieldOperator: address(this) }); - vm.expectRevert("ZkBobCompoundingPool: interest receiver should not be address(0) for existed yield"); + vm.expectRevert("ZkBobCompounding: zero interest receiver"); pool.updateYieldParams(yieldParams); } @@ -1050,7 +1042,7 @@ abstract contract AbstractZkBobPoolTest is AbstractForkTest { ); vm.prank(user2); - vm.expectRevert("ZkBobCompoundingPool: Claim is an operator-called method"); + vm.expectRevert("ZkBobCompounding: not authorized"); uint256 claimed = pool.claim(0); vm.warp(block.timestamp + 365 days); @@ -1088,7 +1080,7 @@ abstract contract AbstractZkBobPoolTest is AbstractForkTest { ); vm.prank(user2); - vm.expectRevert("ZkBobCompoundingPool: Claim is an operator-called method"); + vm.expectRevert("ZkBobCompounding: not authorized"); uint256 claimed = pool.claim(0); vm.warp(block.timestamp + 365 days);