Skip to content

Instantly share code, notes, and snippets.

@ajays97
Created December 5, 2022 16:00
Show Gist options
  • Save ajays97/4b1a6260c53b57fa26b681542cba8b75 to your computer and use it in GitHub Desktop.
Save ajays97/4b1a6260c53b57fa26b681542cba8b75 to your computer and use it in GitHub Desktop.
DAOLaunchPad Solidity 0.5.0
pragma solidity ^0.5.0;
contract DAOLaunchpad {
// the name of the launchpad
string public name;
// the address of the owner of the launchpad
address public owner;
// the mapping to track which addresses are 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 description;
// the amount of funds requested in the proposal
uint256 amount;
// the mapping to track how members voted on the proposal
mapping(address => bool) votes;
}
// the mapping to store proposal information
mapping(uint256 => Proposal) public proposals;
// the DAO's balance
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 mapping of members
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 mapping of members
members[_member] = false;
}
// function to create a new proposal
function createProposal(string memory _description, uint256 _amount) public {
// check if the caller is a member of the launchpad
require(members[msg.sender], "Only members can create proposals.");
// create a new Proposal struct
Proposal memory newProposal = Proposal({
proposer: msg.sender,
description: _description,
amount: _amount
});
// add the proposal to the mapping of proposals
proposals[proposals.length] = newProposal;
}
// function to vote on a proposal
function vote(uint256 _proposalId) public {
// check if the caller is a member of the launchpad
require(members[msg.sender], "Only members can vote on proposals.");
// 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 caller has already voted on the proposal
require(!proposal.votes[msg.sender],
// 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);
}
// 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