Created
June 9, 2020 22:10
-
-
Save hayesgm/abd5077dc265d5085672f0b63b092b78 to your computer and use it in GitHub Desktop.
This file contains 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.8; | |
interface Comptroller { | |
function getCompAddress() external view returns (address); | |
function claimComp(address holder) external; | |
function transfer(address dst, uint256 amount) external returns (bool success); | |
} | |
interface Erc20 { | |
function symbol() external returns (string memory); | |
function balanceOf(address) external returns (uint); | |
function transfer(address dst, uint256 amount) external returns (bool success); | |
function approve(address spender, uint256 amount) external returns (bool success); | |
} | |
interface Fauceteer { | |
function drip(Erc20 token) external; | |
} | |
interface CToken is Erc20 { | |
function underlying() external returns (Erc20); | |
function mint(uint mintAmount) external returns (uint); | |
} | |
contract Collector { | |
Fauceteer public immutable fauceteer; | |
address public immutable owner; | |
Erc20 public immutable comp; | |
Comptroller public immutable comptroller; | |
mapping(string => CToken) public cTokens; | |
constructor(Fauceteer fauceteer_, Comptroller comptroller_, CToken[] memory cTokens_) public { | |
owner = msg.sender; | |
fauceteer = fauceteer_; | |
comptroller = comptroller_; | |
comp = Erc20(comptroller_.getCompAddress()); | |
for (uint i = 0; i < cTokens_.length; i++) { | |
CToken cToken = cTokens_[i]; | |
cTokens[cToken.symbol()] = cToken; | |
Erc20 underlying = cToken.underlying(); | |
underlying.approve(address(cToken), uint(-1)); | |
} | |
} | |
function collect(string calldata token) external { | |
CToken cToken = cTokens[token]; | |
require(address(cToken) != address(0), "cToken not found"); | |
Erc20 underlying = cToken.underlying(); | |
fauceteer.drip(underlying); | |
uint balance = underlying.balanceOf(address(this)); | |
require(cToken.mint(balance) == 0, "mint failed"); | |
} | |
function expend() external { | |
comptroller.claimComp(address(this)); | |
uint balance = comp.balanceOf(address(this)); | |
require(comp.transfer(owner, balance), "transfer failed"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment