-
Notifications
You must be signed in to change notification settings - Fork 2
/
wallet_flat.sol
95 lines (71 loc) · 2.23 KB
/
wallet_flat.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
94
95
// File: contracts/interfaces/ICEther.sol
pragma solidity >=0.4.21 <0.6.0;
interface ICEther {
function mint() external payable;
function redeemUnderlying(uint redeemAmount) external returns (uint);
function balanceOfUnderlying(address owner) external returns (uint);
}
// File: contracts/CEtherLendingLibraryBase.sol
pragma solidity >=0.4.21 <0.6.0;
contract CEtherLendingLibraryBase {
ICEther public cEther;
uint256 public lendedAmount;
constructor(ICEther _cEther) public {
cEther = _cEther;
}
function _lend(uint amount) internal returns (bool) {
cEther.mint.value(amount)();
// require(error == 0, 'got some error from compound');
lendedAmount += amount;
return true;
}
function _withdraw(uint amount) internal returns (bool) {
uint error = cEther.redeemUnderlying(amount);
if (error != 0) {
return false;
}
lendedAmount -= amount;
return true;
}
function interest() public returns (uint) {
uint wholeBalance = cEther.balanceOfUnderlying(address(this));
if (wholeBalance <= lendedAmount) {
return 0;
}
return wholeBalance - lendedAmount;
}
function _withdrawInterest() internal returns (uint _interest) {
_interest = interest();
_withdraw(_interest);
}
function() external payable {
}
}
// File: contracts/Wallet.sol
pragma solidity >=0.4.21 <0.6.0;
contract Wallet is CEtherLendingLibraryBase {
address payable public pool;
uint public denomination;
mapping(address => bool) public deposits;
constructor (ICEther _cEther, uint _denomination, address payable _pool) CEtherLendingLibraryBase(_cEther) public {
pool = _pool;
denomination = _denomination;
}
function enter() public payable {
require(msg.value == denomination, "provide the required value");
deposits[msg.sender] = true;
_lend(msg.value);
emit Debug(msg.sender, deposits[msg.sender]);
}
event Debug(address who, bool done);
function exit() public {
require(deposits[msg.sender], "there is no deposits to withdraw");
deposits[msg.sender] = false;
_withdraw(denomination);
msg.sender.transfer(denomination);
}
function withdrawInterest() public {
uint interest = _withdrawInterest();
pool.transfer(interest);
}
}