-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGovern.sol
More file actions
43 lines (33 loc) · 1.14 KB
/
Govern.sol
File metadata and controls
43 lines (33 loc) · 1.14 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
// SPDX-License-Identifier: MIT
pragma solidity 0.7.5;
import "./ERC20.sol";
contract Govern is ERC20 {
IERC20 constant DAI = IERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F);
mapping(address => bool) hasVoted;
struct Proposal {
uint yesCount;
uint noCount;
mapping(address => bool) hasVoted;
}
uint numProposals;
mapping(uint => Proposal) public proposals;
constructor() ERC20("Govern", "GOV") {}
function buy(uint _amount) external {
DAI.transferFrom(msg.sender, address(this), _amount);
_mint(msg.sender, _amount);
}
function sell(uint _amount) external {
_burn(msg.sender, _amount);
DAI.transfer(msg.sender, _amount);
}
function vote(uint _proposalId, bool _supports) external {
require(!hasVoted[msg.sender]);
Proposal storage proposal = proposals[_proposalId];
if(_supports) {
proposal.yesCount += balanceOf(msg.sender);
} else {
proposal.noCount += balanceOf(msg.sender);
}
proposal.hasVoted[msg.sender] = _supports;
}
}