-
Notifications
You must be signed in to change notification settings - Fork 3
/
raw_timecontroller_v2_inv.sol
69 lines (58 loc) · 2.33 KB
/
raw_timecontroller_v2_inv.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
pragma solidity ^0.5.0;
import "./SafeMath.sol";
import "./Libraries/IERC20.sol";
//import "./Libraries/Lib.sol";
import "./Libraries/VeriSolContracts.sol";
contract TimelockController is IERC20 {
struct Proposal {
uint256 sTime;
address newOwner;
}
address internal owner;
IERC20 votingToken;
address[] internal votedProposals;
Proposal internal proposal;
uint256 internal lockedFunds;
function votedProposal(address voter) internal returns (address[] memory) {
votedProposals.push(voter);
return votedProposals;
}
function getAllProposals() internal returns (address[] memory) {
return votedProposals;
}
function findHighest(address[] memory votedProposals) internal returns (address){
address highestProposal;
uint256 highestAmount;
highestAmount = 0;
for (uint i=0; i<votedProposals.length; i++) {
uint256 accountBalance = votingToken.balanceOf(votedProposals[i]);
if (accountBalance > highestAmount) {
highestAmount = accountBalance;
highestProposal = votedProposals[i];
}
}
return highestProposal;
}
function startExecute() external {
require(proposal.sTime == 0,"on-going proposal");
proposal = Proposal(block.timestamp, msg.sender);
}
function execute(uint amount) external {
require(proposal.sTime + 24 > block.timestamp, "execution has ended");
votingToken.transferFrom(msg.sender, address(this), amount);
votedProposal(msg.sender);
}
function endExecute() external {
require(proposal.sTime != 0, "no proposal");
require(proposal.sTime + 24 < block.timestamp, "execution has not ended");
require(votingToken.balanceOf(address(this))*2 > votingToken.totalSupply(), "execution failed");
//SmartInv inferred:
lockedFunds = votingToken.balanceOf(address(this));
assert(lockedFunds == VeriSol.Old(lockedFunds));
owner = findHighest(getAllProposals());
delete proposal;
}
function rewardFunds() public returns (uint256) {
return lockedFunds;
}
}