-
Notifications
You must be signed in to change notification settings - Fork 1
/
aDaiGateway4.sol
93 lines (80 loc) · 2.66 KB
/
aDaiGateway4.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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) public view returns (uint256);
function transfer(address _to, uint256 _value) public returns (bool);
function approve(address _spender, uint256 _value) public returns (bool);
}
contract Exchange {
function sellAllAmountPayEth(
address otc,
address wethToken,
address buyToken,
uint256 minBuyAmt
) public payable returns (uint256 buyAmt);
}
contract LendingPool {
function deposit( address _reserve, uint256 _amount, uint16 _referralCode) external payable;
}
contract aDaiGateway is Ownable {
Exchange constant DaiEx = Exchange(0x793EbBe21607e4F04788F89c7a9b97320773Ec59);
LendingPool constant lendingPool = LendingPool(0x398eC7346DcD622eDc5ae82352F02bE94C62d119);
Erc20 constant dai = Erc20(0x6B175474E89094C44Da98b954EedeAC495271d0F);
Erc20 constant aDai = Erc20(0xfC1E690f61EFd961294b3e1Ce3313fBD8aa4f85d);
uint16 constant referral = 47;
constructor() public {
dai.approve(0x3dfd23A6c5E8BbcFc9581d2E864a68feb6a076d3, uint256(-1)); //lendingPoolCore
}
function() external payable {
etherToaDai(msg.sender);
}
function etherToaDai(address to)
public
payable
returns (uint256 outAmount)
{
uint256 amount = DaiEx.sellAllAmountPayEth.value(
(msg.value * 994) / 1000
)(
0x794e6e91555438aFc3ccF1c5076A74F42133d08D,
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,
0x6B175474E89094C44Da98b954EedeAC495271d0F,
1
);
lendingPool.deposit(address(dai), amount, referral);
outAmount = aDai.balanceOf(address(this));
aDai.transfer(to, outAmount);
}
function makeprofit() public {
owner.transfer(address(this).balance);
}
}