Skip to content

Commit d90a7ee

Browse files
authored
Create EthereumBridgeDAO.sol
1 parent 7ebaee6 commit d90a7ee

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

contracts/EthereumBridgeDAO.sol

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5+
import "@openzeppelin/contracts/access/Ownable.sol";
6+
7+
contract EthereumBridgeDAO is Ownable {
8+
struct Proposal {
9+
string description;
10+
uint256 voteCount;
11+
mapping(address => bool) voters;
12+
bool executed;
13+
}
14+
15+
IERC20 public token; // The ERC20 token used for voting
16+
Proposal[] public proposals;
17+
uint256 public proposalCount;
18+
uint256 public votingPeriod; // Duration for voting
19+
uint256 public quorum; // Minimum votes required for execution
20+
21+
event ProposalCreated(uint256 proposalId, string description);
22+
event Voted(uint256 proposalId, address voter);
23+
event ProposalExecuted(uint256 proposalId);
24+
event TokensLocked(address indexed user, uint256 amount, string destinationChain);
25+
26+
constructor(address _token, uint256 _votingPeriod, uint256 _quorum) {
27+
token = IERC20(_token);
28+
votingPeriod = _votingPeriod;
29+
quorum = _quorum;
30+
}
31+
32+
modifier proposalExists(uint256 _proposalId) {
33+
require(_proposalId < proposalCount, "Proposal does not exist");
34+
_;
35+
}
36+
37+
modifier notVoted(uint256 _proposalId) {
38+
require(!proposals[_proposalId].voters[msg.sender], "You have already voted");
39+
_;
40+
}
41+
42+
modifier notExecuted(uint256 _proposalId) {
43+
require(!proposals[_proposalId].executed, "Proposal already executed");
44+
_;
45+
}
46+
47+
function createProposal(string memory _description) external onlyOwner {
48+
Proposal storage newProposal = proposals.push();
49+
newProposal.description = _description;
50+
newProposal.voteCount = 0;
51+
newProposal.executed = false;
52+
proposalCount++;
53+
54+
emit ProposalCreated(proposalCount - 1, _description);
55+
}
56+
57+
function vote(uint256 _proposalId) external
58+
proposalExists(_proposalId)
59+
notVoted(_proposalId)
60+
notExecuted(_proposalId)
61+
{
62+
Proposal storage proposal = proposals[_proposalId];
63+
proposal.voters[msg.sender] = true;
64+
proposal.voteCount++;
65+
66+
emit Voted(_proposalId, msg.sender);
67+
}
68+
69+
function executeProposal(uint256 _proposalId) external
70+
proposalExists(_proposalId)
71+
notExecuted(_proposalId)
72+
{
73+
Proposal storage proposal = proposals[_proposalId];
74+
require(proposal.voteCount >= quorum, "Not enough votes to execute proposal");
75+
76+
proposal.executed = true;
77+
78+
emit ProposalExecuted(_proposalId);
79+
}
80+
81+
function lockTokens(uint256 amount, string memory destinationChain) external {
82+
require(token.balanceOf(msg.sender) >= amount, "Insufficient balance");
83+
token.transferFrom(msg.sender, address(this), amount);
84+
emit TokensLocked(msg.sender, amount, destinationChain);
85+
}
86+
87+
// Function to unlock tokens (to be called by the bridge)
88+
function unlockTokens(address user, uint256 amount) external onlyOwner {
89+
token.transfer(user, amount);
90+
}
91+
92+
function getProposal(uint256 _proposalId) external view
93+
proposalExists(_proposalId)
94+
returns (string memory, uint256, bool)
95+
{
96+
Proposal storage proposal = proposals[_proposalId];
97+
return (proposal.description, proposal.voteCount, proposal.executed);
98+
}
99+
100+
function getProposalCount() external view returns (uint256) {
101+
return proposalCount;
102+
}
103+
}

0 commit comments

Comments
 (0)