-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommodityDAO.sol
More file actions
75 lines (64 loc) · 2.21 KB
/
CommodityDAO.sol
File metadata and controls
75 lines (64 loc) · 2.21 KB
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
// File: CommodityDAO.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./BondingCurveToken.sol";
import "./StakingVault.sol";
contract CommodityDAO {
BondingCurveToken public token;
StakingVault public vault;
uint256 public epochDuration = 8 hours;
struct Proposal {
uint256 newTaxBP;
uint256 startTime;
uint256 yes;
uint256 no;
bool executed;
mapping(address => bool) voted;
}
uint256 public proposalCount;
mapping(uint256 => Proposal) public proposals;
address[5] public barons;
event ProposalCreated(uint256 id, uint256 newTaxBP);
event Voted(uint256 id, address voter, bool support);
event Executed(uint256 id);
constructor(BondingCurveToken _token, StakingVault _vault) {
token = _token;
vault = _vault;
}
function updateBarons() public {
barons = vault.getTopStakers();
}
function proposeTaxChange(uint256 newTaxBP) external {
updateBarons();
require(isBaron(msg.sender), "Not a baron");
proposalCount++;
Proposal storage p = proposals[proposalCount];
p.newTaxBP = newTaxBP;
p.startTime = block.timestamp;
emit ProposalCreated(proposalCount, newTaxBP);
}
function vote(uint256 pid, bool support) external {
Proposal storage p = proposals[pid];
require(block.timestamp <= p.startTime + epochDuration, "Voting ended");
require(isBaron(msg.sender), "Not a baron");
require(!p.voted[msg.sender], "Already voted");
p.voted[msg.sender] = true;
if (support) p.yes++; else p.no++;
emit Voted(pid, msg.sender, support);
}
function execute(uint256 pid) external {
Proposal storage p = proposals[pid];
require(block.timestamp > p.startTime + epochDuration, "Epoch not ended");
require(!p.executed, "Already executed");
require(p.yes > p.no, "Not passed");
token.setTaxBP(p.newTaxBP);
p.executed = true;
emit Executed(pid);
}
function isBaron(address addr) public view returns (bool) {
for (uint i = 0; i < 5; i++) {
if (barons[i] == addr) return true;
}
return false;
}
}