update cPool

This commit is contained in:
Alexey 2021-03-10 20:28:44 +04:00
parent 4069b61421
commit 78bd4175fa
3 changed files with 25 additions and 80 deletions

View File

@ -1,14 +0,0 @@
dist: trusty
language: node_js
node_js:
- '11'
install:
- npm ci
- cp .env.example .env
- travis_wait 30 npm run build
- npx ganache-cli > /dev/null &
- npm run migrate:dev
script:
- npm run test
- npm run eslint
- node cli.js test

View File

@ -13,23 +13,26 @@
pragma solidity ^0.6.0;
import "./Tornado.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
contract ERC20Tornado is Tornado {
address public token;
using SafeERC20 for IERC20;
IERC20 public immutable token;
constructor(
IVerifier _verifier,
IHasher _hasher,
uint256 _denomination,
uint32 _merkleTreeHeight,
address _token
IERC20 _token
) public Tornado(_verifier, _hasher, _denomination, _merkleTreeHeight) {
token = _token;
}
function _processDeposit() internal override {
require(msg.value == 0, "ETH value is supposed to be 0 for ERC20 instance");
_safeErc20TransferFrom(msg.sender, address(this), denomination);
token.safeTransferFrom(msg.sender, address(this), denomination);
}
function _processWithdraw(
@ -40,9 +43,9 @@ contract ERC20Tornado is Tornado {
) internal override {
require(msg.value == _refund, "Incorrect refund amount received by the contract");
_safeErc20Transfer(_recipient, denomination - _fee);
token.safeTransfer(_recipient, denomination - _fee);
if (_fee > 0) {
_safeErc20Transfer(_relayer, _fee);
token.safeTransfer(_relayer, _fee);
}
if (_refund > 0) {
@ -53,47 +56,4 @@ contract ERC20Tornado is Tornado {
}
}
}
function _safeErc20TransferFrom(
address _from,
address _to,
uint256 _amount
) internal {
(bool success, bytes memory data) =
token.call(
abi.encodeWithSelector(
0x23b872dd, /* transferFrom */
_from,
_to,
_amount
)
);
require(success, "not enough allowed tokens");
// if contract returns some data lets make sure that is `true` according to standard
if (data.length > 0) {
require(data.length == 32, "data length should be either 0 or 32 bytes");
success = abi.decode(data, (bool));
require(success, "not enough allowed tokens. Token returns false.");
}
}
function _safeErc20Transfer(address _to, uint256 _amount) internal {
(bool success, bytes memory data) =
token.call(
abi.encodeWithSelector(
0xa9059cbb, /* transfer */
_to,
_amount
)
);
require(success, "not enough tokens");
// if contract returns some data lets make sure that is `true` according to standard
if (data.length > 0) {
require(data.length == 32, "data length should be either 0 or 32 bytes");
success = abi.decode(data, (bool));
require(success, "not enough tokens. Token returns false.");
}
}
}

View File

@ -12,28 +12,27 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
interface IComptroller {
function claimComp(address holder) external;
}
import "./ERC20Tornado.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IComptroller {
function transfer(address dst, uint rawAmount) external returns (bool);
function balanceOf(address owner) external;
}
contract ERC20Tornado is Tornado {
IComptroller public comptroller;
contract cPool is ERC20Tornado {
address public immutable governance = 0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce;
ICOMP public immutable COMP = 0xc00e94Cb662C3520282E6f5717214004A7f26888;
IERC20 public immutable comp;
constructor(IComptroller _comptroller, ICOMP _comp) public {
comptroller = _comptroller;
COMP = _comp;
constructor(
IERC20 _comp,
IVerifier _verifier,
IHasher _hasher,
uint256 _denomination,
uint32 _merkleTreeHeight,
IERC20 _token
) ERC20Tornado(_verifier, _hasher, _denomination, _merkleTreeHeight, _token) public {
comp = _comp;
}
function moveYeild() {
comp.claimComp(address(this));
uint balance = COMP.balanceOf(address(this));
COMP.transfer(governance, balance);
/// @dev Moves earned yield of the COMP token to the tornado governance contract
/// To make it work you may need to call `comptroller.claimComp(cPoolAddress)` before
function claimComp() external {
comp.transfer(governance, comp.balanceOf(address(this)));
}
}