-
Notifications
You must be signed in to change notification settings - Fork 0
/
DNamesDAO.sol
80 lines (62 loc) · 2.43 KB
/
DNamesDAO.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/governance/Governance.sol";
contract dNamesDAO is Governance {
struct Proposal {
uint256 id;
address proposer;
string description;
uint256 voteCount;
bool executed;
bool isBlockProposal;
}
mapping(uint256 => Proposal) public proposals;
uint256 public proposalCounter;
mapping(address => uint256) public votes;
address public dnsAddress;
address public oracleAddress;
mapping(string => bool) public blockedDomains;
event ProposalCreated(uint256 indexed proposalId, address indexed proposer);
event Voted(uint256 indexed proposalId, address indexed voter, uint256 voteCount);
event ProposalExecuted(uint256 indexed proposalId);
event DomainBlocked(string domainName);
constructor(address dns) {
dnsAddress = dns;
}
modifier onlyDNS() {
require(msg.sender == dnsAddress, "Only the dNamesDNS contract can call this function.");
_;
}
function createProposal(string memory description, bool isBlockProposal) external onlyDNS returns (uint256) {
uint256 proposalId = _createProposal();
proposals[proposalId] = Proposal({
id: proposalId,
proposer: msg.sender,
description: description,
voteCount: 0,
executed: false,
isBlockProposal: isBlockProposal
});
emit ProposalCreated(proposalId, msg.sender);
return proposalId;
}
function vote(uint256 proposalId, uint256 voteCount) external onlyDNS {
require(!proposals[proposalId].executed, "Proposal has already been executed.");
votes[msg.sender] = voteCount;
proposals[proposalId].voteCount += voteCount;
emit Voted(proposalId, msg.sender, voteCount);
}
function executeProposal(uint256 proposalId) external onlyDNS {
Proposal storage proposal = proposals[proposalId];
require(!proposal.executed, "Proposal has already been executed.");
if (proposal.isBlockProposal && proposal.voteCount > totalSupply() / 2) {
blockedDomains[proposal.description] = true;
emit DomainBlocked(proposal.description);
}
proposal.executed = true;
emit ProposalExecuted(proposalId);
}
function setOracleAddress(address oracle) external onlyDNS {
oracleAddress = oracle;
}
}