Created
December 6, 2023 14:39
-
-
Save fanbyprinciple/e7dcc54bf05f33fe6d9ec4e683c27848 to your computer and use it in GitHub Desktop.
mudmdumud
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| contracts/MyDAO.sol | |
| // SPDX-License-Identifier: UNLICENSED | |
| pragma solidity ^0.8.0; | |
| contract MyDAO { | |
| mapping(address => uint256) private _balances; | |
| mapping(address => bool) private _hasInitialized; | |
| uint256 public specialTokens = 6000; | |
| uint256 public nextProposalId; | |
| mapping(uint256 => Proposal) public proposals; | |
| struct Proposal { | |
| string description; | |
| bool executed; | |
| uint256 voteCount; | |
| mapping(address => uint256) votes; | |
| } | |
| constructor() { | |
| nextProposalId = 0; | |
| } | |
| function initializeAccount() public { | |
| require(!_hasInitialized[msg.sender], "Account already initialized"); | |
| _balances[msg.sender] = 1000; // Initial token balance for each account | |
| _hasInitialized[msg.sender] = true; | |
| } | |
| function transferVotes(address recipient, uint256 amount) public { | |
| require(_balances[msg.sender] >= amount, "Insufficient balance"); | |
| _balances[msg.sender] -= amount; | |
| _balances[recipient] += amount; | |
| } | |
| function createProposal(string memory description) public { | |
| Proposal storage proposal = proposals[nextProposalId]; | |
| proposal.description = description; | |
| proposal.executed = false; | |
| proposal.voteCount = 0; | |
| nextProposalId++; | |
| } | |
| function balanceOf(address account) public view returns (uint256) { | |
| return _balances[account]; | |
| } | |
| function voteOnProposal(uint256 proposalId) public { | |
| Proposal storage proposal = proposals[proposalId]; | |
| uint256 voterBalance = balanceOf(msg.sender); | |
| proposal.votes[msg.sender] += voterBalance; | |
| proposal.voteCount += voterBalance; | |
| } | |
| function executeProposal(uint256 proposalId) public { | |
| Proposal storage proposal = proposals[proposalId]; | |
| require(!proposal.executed, "Proposal already executed"); | |
| require(proposal.voteCount > 2999, "Not enough votes"); | |
| if (keccak256(abi.encodePacked(proposal.description)) == keccak256(abi.encodePacked("Significant Withdrawal"))) { | |
| executeSignificantWithdrawal(); | |
| } | |
| proposal.executed = true; | |
| } | |
| function executeSignificantWithdrawal() private { | |
| uint256 withdrawalAmount = specialTokens; | |
| _balances[msg.sender] += withdrawalAmount; | |
| _balances[address(this)] = 0; | |
| specialTokens = 0; | |
| } | |
| function isSolved() public view returns (bool) { | |
| if (specialTokens == 0) { | |
| return true; | |
| } else { | |
| return false; | |
| } | |
| } | |
| } | |
| contracts/MyDAO.sol | |
| // SPDX-License-Identifier: UNLICENSED | |
| pragma solidity ^0.8.0; | |
| contract MyDAO { | |
| mapping(address => uint256) private _balances; | |
| mapping(address => bool) private _hasInitialized; | |
| uint256 public specialTokens = 6000; | |
| uint256 public nextProposalId; | |
| mapping(uint256 => Proposal) public proposals; | |
| struct Proposal { | |
| string description; | |
| bool executed; | |
| uint256 voteCount; | |
| mapping(address => uint256) votes; | |
| } | |
| constructor() { | |
| nextProposalId = 0; | |
| } | |
| function initializeAccount() public { | |
| require(!_hasInitialized[msg.sender], "Account already initialized"); | |
| _balances[msg.sender] = 1000; // Initial token balance for each account | |
| _hasInitialized[msg.sender] = true; | |
| } | |
| function transferVotes(address recipient, uint256 amount) public { | |
| require(_balances[msg.sender] >= amount, "Insufficient balance"); | |
| _balances[msg.sender] -= amount; | |
| _balances[recipient] += amount; | |
| } | |
| function createProposal(string memory description) public { | |
| Proposal storage proposal = proposals[nextProposalId]; | |
| proposal.description = description; | |
| proposal.executed = false; | |
| proposal.voteCount = 0; | |
| nextProposalId++; | |
| } | |
| function balanceOf(address account) public view returns (uint256) { | |
| return _balances[account]; | |
| } | |
| function voteOnProposal(uint256 proposalId) public { | |
| Proposal storage proposal = proposals[proposalId]; | |
| uint256 voterBalance = balanceOf(msg.sender); | |
| proposal.votes[msg.sender] += voterBalance; | |
| proposal.voteCount += voterBalance; | |
| } | |
| function executeProposal(uint256 proposalId) public { | |
| Proposal storage proposal = proposals[proposalId]; | |
| require(!proposal.executed, "Proposal already executed"); | |
| require(proposal.voteCount > 2999, "Not enough votes"); | |
| if (keccak256(abi.encodePacked(proposal.description)) == keccak256(abi.encodePacked("Significant Withdrawal"))) { | |
| executeSignificantWithdrawal(); | |
| } | |
| proposal.executed = true; | |
| } | |
| function executeSignificantWithdrawal() private { | |
| uint256 withdrawalAmount = specialTokens; | |
| _balances[msg.sender] += withdrawalAmount; | |
| _balances[address(this)] = 0; | |
| specialTokens = 0; | |
| } | |
| function isSolved() public view returns (bool) { | |
| if (specialTokens == 0) { | |
| return true; | |
| } else { | |
| return false; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment