-
Notifications
You must be signed in to change notification settings - Fork 1
/
cUSDCGateway2.sol
72 lines (60 loc) · 2.14 KB
/
cUSDCGateway2.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
pragma solidity ^0.4.24;
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract Erc20 {
function balanceOf(address _owner) view public returns(uint256);
function transfer(address _to, uint256 _value) public returns(bool);
function approve(address _spender, uint256 _value) public returns(bool);
}
contract CErc20 is Erc20 {
function mint(uint mintAmount) external returns (uint);
function redeem(uint redeemTokens) external returns (uint);
}
contract Exchange {
function ethToTokenSwapInput(uint256 min_tokens, uint256 deadline) public payable returns (uint256);
}
contract cUSDCGateway is Ownable {
Exchange USDCEx = Exchange(0x97deC872013f6B5fB443861090ad931542878126);
Erc20 USDC = Erc20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
CErc20 cUSDC = CErc20(0x39AA39c021dfbaE8faC545936693aC917d5E7563);
function () public payable {
etherTocUSDC(msg.sender);
}
function etherTocUSDC(address to) public payable returns(uint256 outAmount) {
uint256 amount = USDCEx.ethToTokenSwapInput.value(msg.value * 993 / 1000)(1, now);
cUSDC.mint(amount);
outAmount = cUSDC.balanceOf(address(this));
cUSDC.transfer(to, outAmount);
}
function set() public {
USDC.approve(address(cUSDC), uint256(-1));
}
function makeprofit() public {
owner.transfer(address(this).balance);
}
}