Skip to content

Commit

Permalink
fix: cether return values
Browse files Browse the repository at this point in the history
  • Loading branch information
0xCooki committed Jun 18, 2024
1 parent 4bd6e30 commit f27f6fa
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions contracts/helpers/compound/CompoundV2_CEtherGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pragma solidity ^0.8.17;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import {IWETH} from "@gearbox-protocol/core-v2/contracts/interfaces/external/IWETH.sol";
import {SanityCheckTrait} from "@gearbox-protocol/core-v3/contracts/traits/SanityCheckTrait.sol";
Expand All @@ -15,6 +16,8 @@ import {ICErc20Actions} from "../../integrations/compound/ICErc20.sol";
/// @title CEther gateway
/// @notice Wrapper around CEther that uses WETH for all operations instead of ETH
contract CEtherGateway is SanityCheckTrait, ICErc20Actions, ICompoundV2_Exceptions {
using SafeERC20 for IERC20;

/// @notice WETH token address
address public immutable weth;

Expand Down Expand Up @@ -49,7 +52,7 @@ contract CEtherGateway is SanityCheckTrait, ICErc20Actions, ICompoundV2_Exceptio
error = 0; // U:[CEG-3]

// send cETH to caller
IERC20(ceth).transfer(msg.sender, IERC20(ceth).balanceOf(address(this)));
IERC20(ceth).safeTransfer(msg.sender, IERC20(ceth).balanceOf(address(this)));
}

/// @notice Burn given amount of cETH to withdraw WETH
Expand All @@ -58,7 +61,7 @@ contract CEtherGateway is SanityCheckTrait, ICErc20Actions, ICompoundV2_Exceptio
/// @param error Error code (always zero, added for compatibility)
function redeem(uint256 redeemTokens) external override returns (uint256 error) {
// get specified amount of cETH from caller
IERC20(ceth).transferFrom(msg.sender, address(this), redeemTokens);
IERC20(ceth).safeTransferFrom(msg.sender, address(this), redeemTokens);

// redeem ETH from Compound
error = ICEther(ceth).redeem(redeemTokens); // U:[CEG-4]
Expand All @@ -76,15 +79,15 @@ contract CEtherGateway is SanityCheckTrait, ICErc20Actions, ICompoundV2_Exceptio
/// @return error Error code (always zero, added for compatibility)
function redeemUnderlying(uint256 redeemAmount) external override returns (uint256 error) {
// transfer all cETH from caller
IERC20(ceth).transferFrom(msg.sender, address(this), IERC20(ceth).balanceOf(msg.sender));
IERC20(ceth).safeTransferFrom(msg.sender, address(this), IERC20(ceth).balanceOf(msg.sender));

// redeem ETH from Compound
error = ICEther(ceth).redeemUnderlying(redeemAmount); // U:[CEG-5]
if (error != 0) revert CTokenError(error); // U:[CEG-6]

// return the remaining cETH (if any) back to caller
uint256 cethBalance = IERC20(ceth).balanceOf(address(this));
if (cethBalance > 0) IERC20(ceth).transfer(msg.sender, cethBalance);
if (cethBalance > 0) IERC20(ceth).safeTransfer(msg.sender, cethBalance);

// wrap ETH and send to caller
uint256 ethBalance = address(this).balance;
Expand Down

0 comments on commit f27f6fa

Please sign in to comment.