/
ERC20CompoundPCVDeposit.sol
50 lines (39 loc) · 1.52 KB
/
ERC20CompoundPCVDeposit.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
import "./CompoundPCVDepositBase.sol";
interface CErc20 {
function mint(uint256 amount) external returns (uint256);
function underlying() external returns (address);
}
/// @title ERC-20 implementation for a Compound PCV Deposit
/// @author Fei Protocol
contract ERC20CompoundPCVDeposit is CompoundPCVDepositBase {
/// @notice the token underlying the cToken
IERC20 public token;
/// @notice Compound ERC20 PCV Deposit constructor
/// @param _core Fei Core for reference
/// @param _cToken Compound cToken to deposit
constructor(address _core, address _cToken)
CompoundPCVDepositBase(_core, _cToken)
{
token = IERC20(CErc20(_cToken).underlying());
}
/// @notice deposit ERC-20 tokens to Compound
function deposit() external override whenNotPaused {
uint256 amount = token.balanceOf(address(this));
token.approve(address(cToken), amount);
// Compound returns non-zero when there is an error
require(
CErc20(address(cToken)).mint(amount) == 0,
"ERC20CompoundPCVDeposit: deposit error"
);
emit Deposit(msg.sender, amount);
}
function _transferUnderlying(address to, uint256 amount) internal override {
SafeERC20.safeTransfer(token, to, amount);
}
/// @notice display the related token of the balance reported
function balanceReportedIn() public view override returns (address) {
return address(token);
}
}