Created
December 5, 2022 16:01
-
-
Save ajays97/46f65e96bba3c16867304303842877a1 to your computer and use it in GitHub Desktop.
DAO LaunchPad Solidity 0.8.0
This file contains 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
pragma solidity ^0.8.0; | |
contract DAOLaunchpad { | |
// the name of the launchpad | |
string public name; | |
// the address of the owner of the launchpad | |
address public owner; | |
// the mapping of members of the launchpad | |
mapping(address => bool) public members; | |
// the struct for a proposal | |
struct Proposal { | |
// the address of the proposer | |
address proposer; | |
// the description of the proposal | |
string memory description; | |
// the amount of funds requested in the proposal | |
uint256 amount; | |
// the mapping of votes for the proposal | |
mapping(address => bool) votes; | |
} | |
// the mapping of proposals for the launchpad | |
mapping(uint256 => Proposal) public proposals; | |
// the balance of the launchpad | |
uint256 public balance; | |
// the constructor sets the name and owner of the launchpad | |
constructor(string memory _name) public { | |
name = _name; | |
owner = msg.sender; | |
} | |
// function to transfer ownership of the launchpad | |
function transferOwnership(address _newOwner) public { | |
// only the owner can transfer ownership | |
require(msg.sender == owner, "Only the owner can transfer ownership."); | |
// transfer ownership | |
owner = _newOwner; | |
} | |
// function to add a new member to the launchpad | |
function addMember(address _member) public { | |
// only the owner can add members | |
require(msg.sender == owner, "Only the owner can add members."); | |
// add the member to the members mapping | |
members[_member] = true; | |
} | |
// function to remove a member from the launchpad | |
function removeMember(address _member) public { | |
// only the owner can remove members | |
require(msg.sender == owner, "Only the owner can remove members."); | |
// remove the member from the members mapping | |
delete members[_member]; | |
} | |
// function to create a new proposal | |
function createProposal(string memory _description, uint256 _amount) public { | |
// check if the sender is a member of the launchpad | |
require(members[msg.sender], "Sender is not a member of the launchpad."); | |
// create a new Proposal struct | |
Proposal memory newProposal = Proposal({ | |
proposer: msg.sender, | |
description: _description, | |
amount: _amount | |
}); | |
// add the proposal to the proposals mapping | |
proposals[proposals.length] = newProposal; | |
} | |
// function to vote on a proposal | |
function vote(uint256 _proposalId) public { | |
// check if the sender is a member of the launchpad | |
require(members[msg.sender], "Sender is not a member of the launchpad."); | |
// get the proposal | |
Proposal storage proposal = proposals[_proposalId]; | |
// check if the proposal exists | |
require(proposal.proposer != address(0), "Proposal does not exist."); | |
// add the sender's vote to the proposal | |
proposal.votes[msg.sender] = true; | |
} | |
// function to distribute funds to a proposal | |
function distributeFunds(uint256 _proposalId) public { | |
// only the owner can distribute funds | |
require(msg.sender == owner, "Only the owner can distribute funds."); | |
// get the proposal | |
Proposal storage proposal = proposals[_proposalId]; | |
// check if the proposal exists | |
require(proposal.proposer != address(0), "Proposal does not exist."); | |
// check if the launchpad has enough funds | |
require(proposal.amount <= balance, "The launchpad does not have enough funds."); | |
// distribute the funds to the proposer | |
proposal.proposer.transfer(proposal.amount); | |
// update the launchpad's balance | |
balance -= proposal.amount; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment