Last active
May 1, 2020 19:27
-
-
Save Amxx/0c97058ca08340a8d6b7c3da2f203752 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.6.0; | |
interface IERC20 | |
{ | |
function totalSupply() external view returns (uint256); | |
function balanceOf(address account) external view returns (uint256); | |
function transfer(address recipient, uint256 amount) external returns (bool); | |
function allowance(address owner, address spender) external view returns (uint256); | |
function approve(address spender, uint256 amount) external returns (bool); | |
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
event Approval(address indexed owner, address indexed spender, uint256 value); | |
} | |
interface ICEther is IERC20 | |
{ | |
function redeem(uint redeemTokens) external returns (uint); | |
function redeemUnderlying(uint redeemAmount) external returns (uint); | |
} | |
contract CEtherRedeamer | |
{ | |
ICEther public immutable cether; | |
constructor(address _cether) | |
public | |
{ | |
cether = ICEther(_cether); | |
} | |
receive() | |
external payable | |
{} | |
function redeem(uint redeemTokens) external returns (uint) | |
{ | |
uint result = cether.redeem(redeemTokens); | |
(bool success, bytes memory returndata) = msg.sender.call{value: address(this).balance}(""); | |
require(success, string(returndata)); | |
cether.transfer(msg.sender, cether.balanceOf(address(this))); | |
return result; | |
} | |
function redeemUnderlying(uint redeemAmount) external returns (uint) | |
{ | |
uint result = cether.redeemUnderlying(redeemAmount); | |
(bool success, bytes memory returndata) = msg.sender.call{value: address(this).balance}(""); | |
require(success, string(returndata)); | |
cether.transfer(msg.sender, cether.balanceOf(address(this))); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment