Skip to content

Commit 75bd0b7

Browse files
authored
Update EthereumBridgeDAO.sol
1 parent 9d9e7b8 commit 75bd0b7

File tree

1 file changed

+64
-8
lines changed

1 file changed

+64
-8
lines changed

contracts/EthereumBridgeDAO.sol

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,34 @@ contract EthereumBridgeDAO is Ownable {
1212
bool executed;
1313
}
1414

15-
IERC20 public token; // The ERC20 token used for voting
15+
enum LockStatus { Pending, Released }
16+
17+
struct LockedToken {
18+
address user;
19+
uint256 amount;
20+
string destinationChain;
21+
LockStatus status;
22+
}
23+
24+
IERC20 public token; // The ERC20 token used for locking and unlocking
1625
Proposal[] public proposals;
1726
uint256 public proposalCount;
1827
uint256 public votingPeriod; // Duration for voting
1928
uint256 public quorum; // Minimum votes required for execution
2029

30+
// Mapping to track locked tokens
31+
mapping(uint256 => LockedToken) public lockedTokens;
32+
uint256 public lockedTokenCount;
33+
2134
event ProposalCreated(uint256 proposalId, string description);
2235
event Voted(uint256 proposalId, address voter);
2336
event ProposalExecuted(uint256 proposalId);
24-
event TokensLocked(address indexed user, uint256 amount, string destinationChain);
37+
event TokensLocked(address indexed user, uint256 amount, string destinationChain, uint256 indexed lockId);
38+
event TokensUnlocked(address indexed user, uint256 amount);
39+
event LockStatusUpdated(uint256 indexed lockId, LockStatus status);
2540

2641
constructor(address _token, uint256 _votingPeriod, uint256 _quorum) {
42+
require(_token != address(0), "Token address cannot be zero");
2743
token = IERC20(_token);
2844
votingPeriod = _votingPeriod;
2945
quorum = _quorum;
@@ -44,6 +60,7 @@ contract EthereumBridgeDAO is Ownable {
4460
_;
4561
}
4662

63+
// Function to create a new proposal
4764
function createProposal(string memory _description) external onlyOwner {
4865
Proposal storage newProposal = proposals.push();
4966
newProposal.description = _description;
@@ -54,6 +71,7 @@ contract EthereumBridgeDAO is Ownable {
5471
emit ProposalCreated(proposalCount - 1, _description);
5572
}
5673

74+
// Function to vote on a proposal
5775
function vote(uint256 _proposalId) external
5876
proposalExists(_proposalId)
5977
notVoted(_proposalId)
@@ -66,6 +84,7 @@ contract EthereumBridgeDAO is Ownable {
6684
emit Voted(_proposalId, msg.sender);
6785
}
6886

87+
// Function to execute a proposal
6988
function executeProposal(uint256 _proposalId) external
7089
proposalExists(_proposalId)
7190
notExecuted(_proposalId)
@@ -78,26 +97,63 @@ contract EthereumBridgeDAO is Ownable {
7897
emit ProposalExecuted(_proposalId);
7998
}
8099

100+
// Function to lock tokens for cross-chain transfer
81101
function lockTokens(uint256 amount, string memory destinationChain) external {
102+
require(amount > 0, "Amount must be greater than zero");
82103
require(token.balanceOf(msg.sender) >= amount, "Insufficient balance");
104+
105+
// Transfer tokens to the contract
83106
token.transferFrom(msg.sender, address(this), amount);
84-
emit TokensLocked(msg.sender, amount, destinationChain);
107+
108+
// Record the locked token
109+
lockedTokens[lockedTokenCount] = LockedToken({
110+
user: msg.sender,
111+
amount: amount,
112+
destinationChain: destinationChain,
113+
status: LockStatus.Pending
114+
});
115+
116+
emit TokensLocked(msg.sender, amount, destinationChain, lockedTokenCount);
117+
lockedTokenCount++;
85118
}
86119

87-
// Function to unlock tokens (to be called by the bridge)
120+
// Function to unlock tokens (to be called by the BSC bridge)
88121
function unlockTokens(address user, uint256 amount) external onlyOwner {
122+
require(amount > 0, "Amount must be greater than zero");
89123
token.transfer(user, amount);
124+
emit TokensUnlocked(user, amount);
125+
}
126+
127+
// Function to update the status of a locked token
128+
function updateLockStatus(uint256 lockId, LockStatus status) external onlyOwner {
129+
require(lockId < lockedTokenCount, "Invalid lock ID");
130+
lockedTokens[lockId].status = status;
131+
emit LockStatusUpdated(lockId, status);
132+
}
133+
134+
// Function to get the details of a locked token
135+
function getLockedToken(uint256 lockId) external view returns (address user, uint256 amount, string memory destinationChain, LockStatus status) {
136+
require(lockId < lockedTokenCount, "Invalid lock ID");
137+
LockedToken storage lockedToken = lockedTokens[lockId];
138+
return (lockedToken.user, lockedToken.amount, lockedToken.destinationChain, lockedToken.status);
90139
}
91140

141+
// Function to get the balance of the contract
142+
function getBalance() external view returns (uint256) {
143+
return token.balanceOf(address(this));
144+
}
145+
146+
// Function to get the total number of proposals
147+
function getProposalCount() external view returns (uint256) {
148+
return proposalCount;
149+
}
150+
151+
// Function to get details of a specific proposal
92152
function getProposal(uint256 _proposalId) external view
93153
proposalExists(_proposalId)
94154
returns (string memory, uint256, bool)
95155
{
96156
Proposal storage proposal = proposals[_proposalId];
97157
return (proposal.description, proposal.voteCount, proposal.executed);
98158
}
99-
100-
function getProposalCount() external view returns (uint256) {
101-
return proposalCount;
102-
}
103159
}

0 commit comments

Comments
 (0)