Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Admin committed Nov 29, 2024
1 parent cca5047 commit 37b73f5
Show file tree
Hide file tree
Showing 14 changed files with 385 additions and 416 deletions.
27 changes: 14 additions & 13 deletions src/Badge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ contract Badge is ERC721, Ownable {

// Badge types and their requirements
enum BadgeType {
EARLY_SUPPORTER, // First 100 users to back a project
POWER_BACKER, // Backed more than 5 projects
LIQUIDITY_PROVIDER, // Provided significant liquidity
GOVERNANCE_ACTIVE // Participated in multiple proposals
EARLY_SUPPORTER, // First 100 users to back a project
POWER_BACKER, // Backed more than 5 projects
LIQUIDITY_PROVIDER, // Provided significant liquidity
GOVERNANCE_ACTIVE // Participated in multiple proposals

}

// Mapping from token ID to badge type
mapping(uint256 => BadgeType) public badgeTypes;

// Mapping from address to badge type to whether they have earned it
mapping(address => mapping(BadgeType => bool)) public hasBadge;

// Mapping from badge type to its benefits multiplier (in basis points, 100 = 1%)
mapping(BadgeType => uint256) public badgeBenefits;

Expand All @@ -34,10 +35,10 @@ contract Badge is ERC721, Ownable {
constructor() ERC721("Platform Achievement Badge", "BADGE") Ownable() {
_tokenIds = 0;
// Set initial badge benefits
badgeBenefits[BadgeType.EARLY_SUPPORTER] = 500; // 5% discount
badgeBenefits[BadgeType.POWER_BACKER] = 1000; // 10% discount
badgeBenefits[BadgeType.EARLY_SUPPORTER] = 500; // 5% discount
badgeBenefits[BadgeType.POWER_BACKER] = 1000; // 10% discount
badgeBenefits[BadgeType.LIQUIDITY_PROVIDER] = 1500; // 15% discount
badgeBenefits[BadgeType.GOVERNANCE_ACTIVE] = 750; // 7.5% discount
badgeBenefits[BadgeType.GOVERNANCE_ACTIVE] = 750; // 7.5% discount
}

/**
Expand All @@ -50,7 +51,7 @@ contract Badge is ERC721, Ownable {

_tokenIds++;
uint256 newTokenId = _tokenIds;

_safeMint(recipient, newTokenId);
badgeTypes[newTokenId] = badgeType;
hasBadge[recipient][badgeType] = true;
Expand All @@ -76,14 +77,14 @@ contract Badge is ERC721, Ownable {
*/
function getTotalBenefits(address user) external view returns (uint256) {
uint256 totalBenefit = 0;
for (uint i = 0; i <= uint(type(BadgeType).max); i++) {

for (uint256 i = 0; i <= uint256(type(BadgeType).max); i++) {
BadgeType badgeType = BadgeType(i);
if (hasBadge[user][badgeType]) {
totalBenefit += badgeBenefits[badgeType];
}
}

// Cap total benefit at 25%
return totalBenefit > 2500 ? 2500 : totalBenefit;
}
Expand Down
66 changes: 18 additions & 48 deletions src/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,15 @@ contract Governance is Ownable, ReentrancyGuard {
uint256 public proposalCount;
uint256 public constant VOTING_PERIOD = 7 days;
uint256 public constant EXECUTION_DELAY = 2 days;
uint256 public constant PROPOSAL_THRESHOLD = 100 * 10**18; // 100 tokens needed to create proposal
uint256 public constant PROPOSAL_THRESHOLD = 100 * 10 ** 18; // 100 tokens needed to create proposal

mapping(uint256 => Proposal) public proposals;
mapping(uint256 => uint256) public proposalExecutionTime;

event ProposalCreated(
uint256 indexed proposalId,
address indexed proposer,
string description,
uint256 startTime,
uint256 endTime
);
event VoteCast(
address indexed voter,
uint256 indexed proposalId,
bool support,
uint256 weight
uint256 indexed proposalId, address indexed proposer, string description, uint256 startTime, uint256 endTime
);
event VoteCast(address indexed voter, uint256 indexed proposalId, bool support, uint256 weight);
event ProposalExecuted(uint256 indexed proposalId);

constructor(address _platformToken) Ownable() {
Expand All @@ -59,15 +50,8 @@ contract Governance is Ownable, ReentrancyGuard {
* @param target Address of contract to call if proposal passes
* @param callData Function call data to execute if proposal passes
*/
function createProposal(
string memory description,
address target,
bytes memory callData
) external {
require(
platformToken.balanceOf(msg.sender) >= PROPOSAL_THRESHOLD,
"Insufficient tokens to create proposal"
);
function createProposal(string memory description, address target, bytes memory callData) external {
require(platformToken.balanceOf(msg.sender) >= PROPOSAL_THRESHOLD, "Insufficient tokens to create proposal");
require(target != address(0), "Invalid target address");

uint256 startTime = block.timestamp;
Expand All @@ -83,13 +67,7 @@ contract Governance is Ownable, ReentrancyGuard {
newProposal.target = target;
newProposal.callData = callData;

emit ProposalCreated(
proposalCount,
msg.sender,
description,
startTime,
endTime
);
emit ProposalCreated(proposalCount, msg.sender, description, startTime, endTime);
}

/**
Expand All @@ -111,7 +89,7 @@ contract Governance is Ownable, ReentrancyGuard {
require(votes > 0, "No voting power");

proposal.hasVoted[msg.sender] = true;

if (support) {
proposal.forVotes += votes;
} else {
Expand All @@ -130,19 +108,19 @@ contract Governance is Ownable, ReentrancyGuard {
require(block.timestamp > proposal.endTime, "Voting period not ended");
require(!proposal.executed, "Proposal already executed");
require(proposal.forVotes > proposal.againstVotes, "Proposal rejected");

// Check execution delay
if (proposalExecutionTime[proposalId] == 0) {
proposalExecutionTime[proposalId] = block.timestamp + EXECUTION_DELAY;
return;
}

require(block.timestamp >= proposalExecutionTime[proposalId], "Execution delay not met");

proposal.executed = true;

// Execute the proposal's action
(bool success, ) = proposal.target.call(proposal.callData);
(bool success,) = proposal.target.call(proposal.callData);
require(success, "Proposal execution failed");

emit ProposalExecuted(proposalId);
Expand All @@ -157,20 +135,12 @@ contract Governance is Ownable, ReentrancyGuard {
* @return endTime End time of voting period
* @return executed Whether the proposal has been executed
*/
function getProposal(uint256 proposalId) external view returns (
uint256 forVotes,
uint256 againstVotes,
uint256 startTime,
uint256 endTime,
bool executed
) {
function getProposal(uint256 proposalId)
external
view
returns (uint256 forVotes, uint256 againstVotes, uint256 startTime, uint256 endTime, bool executed)
{
Proposal storage proposal = proposals[proposalId];
return (
proposal.forVotes,
proposal.againstVotes,
proposal.startTime,
proposal.endTime,
proposal.executed
);
return (proposal.forVotes, proposal.againstVotes, proposal.startTime, proposal.endTime, proposal.executed);
}
}
Loading

0 comments on commit 37b73f5

Please sign in to comment.