-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcoinBox.sol
53 lines (44 loc) · 1.42 KB
/
coinBox.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
pragma solidity 0.4.26;
contract coinBox {
address owner;
uint256 fundLimit;
uint256 initialTime;
constructor(uint256 _limit_amount) public {
owner = msg.sender;
fundLimit = _limit_amount;
initialTime = block.timestamp;
}
modifier ownerOnly() {
require(owner == msg.sender);
_;
}
function insertFunds() external payable returns (bool) {
require(msg.value > 0);
require(address(this).balance <= fundLimit);
return true;
}
function withdrawFunds(uint256 _amount) external payable ownerOnly() returns (bool) {
require(_amount > 0);
require(_amount <= maxWithAllowed());
owner.transfer(_amount);
return true;
}
function maxWithAllowed() public view returns (uint256) {
uint256 maxMonthCoins = fundLimit / 10; /* 10% */
uint256 monthsEclipsed = (block.timestamp - initialTime) / (30 days);
uint256 max = 0;
if (maxMonthCoins * monthsEclipsed > fundLimit - address(this).balance) {
max = maxMonthCoins * monthsEclipsed - (fundLimit - address(this).balance);
}
if (max > fundLimit) {
max = fundLimit;
}
return max;
}
function showBalance() public view returns (uint256) {
return address(this).balance;
}
function showInitialTime() public view returns (uint256) {
return initialTime;
}
}