Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
k1rill-fedoseev committed Sep 22, 2023
1 parent 8eae668 commit 3d7474e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 38 deletions.
14 changes: 5 additions & 9 deletions src/zkbob/ZkBobCompoundingMixin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pragma solidity 0.8.15;

import "@openzeppelin/contracts/interfaces/IERC4626.sol";
import "./ZkBobPool.sol";

/**
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
23 changes: 11 additions & 12 deletions src/zkbob/ZkBobPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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()];
}
Expand Down
26 changes: 9 additions & 17 deletions test/zkbob/ZkBobPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 3d7474e

Please sign in to comment.