Skip to content

Commit

Permalink
feat: badic governance layout
Browse files Browse the repository at this point in the history
  • Loading branch information
yarre-uk committed Jun 17, 2024
1 parent 6185a1b commit 769a6c2
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 24 deletions.
1 change: 0 additions & 1 deletion contracts/ERC20/TradableERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.24;

import { VotingERC20 } from "./VotingERC20.sol";
import "hardhat/console.sol";

contract TradableERC20 is VotingERC20 {
uint256 public feePercentage = 1; // 0.01%
Expand Down
3 changes: 1 addition & 2 deletions contracts/ERC20/VotingERC20.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import { VotingLinkedList, Data } from "../utils/VotingLinkedList.sol";
import { VotingLinkedList, Data } from "./utils/VotingLinkedList.sol";
import { BaseERC20 } from "./BaseERC20.sol";
import "hardhat/console.sol";

contract VotingERC20 is BaseERC20, VotingLinkedList {
uint256 private _voteForExistingTokenAmount = 5; // 0.05% of total supply
Expand Down
File renamed without changes.
58 changes: 58 additions & 0 deletions contracts/Governance/MyGovernance.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import { YarreToken } from "../ERC20/YarreToken.sol";
import { RaffleExtended } from "../Raffle/RaffleExtended.sol";
import { ProposalStorage, Proposal, State } from "./ProposalStorage.sol";

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";
import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol";

contract MyGovernance is Ownable, AccessControl, Initializable {
bytes32 public constant EXECUTER_ROLE = keccak256("EXECUTER_ROLE");

YarreToken public token;
RaffleExtended public raffle;

uint256 public percentageForProposal;

uint256 public blockBeforeVoting;
uint256 public blockBeforeExecution;

State private state;

Check failure on line 23 in contracts/Governance/MyGovernance.sol

View workflow job for this annotation

GitHub Actions / codestyle

'state' should start with _

using ProposalStorage for State;

event ProposalCreated(bytes32 id, uint256 percentage);
event ProposalVoted(bytes32 id, address voter);
event ProposalExecuted(bytes32 id);

error UnauthorizedExecuter(address caller);

constructor() Ownable(msg.sender) {}

function initialize(
address payable _token,
address _raffle
) public initializer onlyOwner {
token = YarreToken(_token);
raffle = RaffleExtended(_raffle);

percentageForProposal = 100;
blockBeforeVoting = 300;
blockBeforeExecution = 300;
}

modifier hasEnoughPercentage(uint256 _percentageCap) {
require(
token.userPercentage() >= _percentageCap,
"MyGovernance: not enough percentage"
);
_;
}

function grantRoleExecuter(address account) public onlyOwner {
grantRole(EXECUTER_ROLE, account);
}
}
67 changes: 67 additions & 0 deletions contracts/Governance/ProposalStorage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

struct State {
mapping(bytes32 => Proposal) proposals;
bytes32 lastProposalId;
}

struct Proposal {
uint256 id;
address sender;
uint256 proposedAt;
uint256 votingStartedAt;
bool executed;
}

library ProposalStorage {
function getId(Proposal memory _params) internal pure returns (bytes32) {
return
keccak256(
abi.encodePacked(
_params.id,
_params.sender,
_params.proposedAt,
_params.votingStartedAt,
_params.executed
)
);
}

function isEmpty(
State storage state,
bytes32 id
) internal view returns (bool) {
return state.proposals[id].sender == address(0);
}

function addData(
State storage state,
Proposal memory _Proposal

Check failure on line 40 in contracts/Governance/ProposalStorage.sol

View workflow job for this annotation

GitHub Actions / codestyle

Function param name must be in mixedCase

Check failure on line 40 in contracts/Governance/ProposalStorage.sol

View workflow job for this annotation

GitHub Actions / codestyle

Variable name must be in mixedCase
) internal returns (bytes32) {
bytes32 id = getId(_Proposal);
state.proposals[id] = _Proposal;
state.lastProposalId = id;

return id;
}

function getData(
State storage state,
bytes32 id
) internal view returns (Proposal memory) {
return state.proposals[id];
}

function updateData(
State storage state,
bytes32 id,
Proposal memory _Proposal

Check failure on line 59 in contracts/Governance/ProposalStorage.sol

View workflow job for this annotation

GitHub Actions / codestyle

Function param name must be in mixedCase

Check failure on line 59 in contracts/Governance/ProposalStorage.sol

View workflow job for this annotation

GitHub Actions / codestyle

Variable name must be in mixedCase
) internal {
state.proposals[id] = _Proposal;
}

function removeData(State storage state, bytes32 id) internal {
delete state.proposals[id];
}
}
7 changes: 7 additions & 0 deletions contracts/Raffle/RaffleExtended.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ contract RaffleExtended is Raffle {
address public founder;
address public staking;

event XChanged(uint256 X);
event YChanged(uint256 Y);
event ZChanged(uint256 Z);

function setWaitingForRandomness(
bool _waitingForRandomness
) public onlyOwner {
Expand Down Expand Up @@ -54,14 +58,17 @@ contract RaffleExtended is Raffle {

function setX(uint256 _X) public onlyOwner {
X = _X;
emit XChanged(_X);
}

function setY(uint256 _Y) public onlyOwner {
Y = _Y;
emit YChanged(_Y);
}

function setZ(uint256 _Z) public onlyOwner {
Z = _Z;
emit ZChanged(_Z);
}

function setFounder(address _founder) public onlyOwner {
Expand Down
File renamed without changes.
43 changes: 22 additions & 21 deletions report_outfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
| contracts/ERC20/TradableERC20.sol | [object Promise] |
| contracts/ERC20/VotingERC20.sol | [object Promise] |
| contracts/ERC20/YarreToken.sol | [object Promise] |
| contracts/Governance/MyGovernance.sol | [object Promise] |
| contracts/Governance/ProposalStorage.sol | [object Promise] |
| contracts/interfaces/IWETH.sol | [object Promise] |
| contracts/Raffle/DepositStorage.sol | [object Promise] |
| contracts/Raffle/MyProxy.sol | [object Promise] |
| contracts/Raffle/Raffle.sol | [object Promise] |
| contracts/Raffle/RaffleExtended.sol | [object Promise] |
| contracts/utils/VotingLinkedList.sol | [object Promise] |
| contracts/utils/MyProxy.sol | [object Promise] |


### Contracts Description Table
Expand Down Expand Up @@ -76,6 +77,19 @@
| **YarreToken** | Implementation | TradableERC20 |||
|| <Constructor> | Public ❗️ | 🛑 | TradableERC20 |
||||||
| **MyGovernance** | Implementation | Ownable, AccessControl, Initializable |||
|| <Constructor> | Public ❗️ | 🛑 | Ownable |
|| initialize | Public ❗️ | 🛑 | initializer onlyOwner |
|| grantRoleExecuter | Public ❗️ | 🛑 | onlyOwner |
||||||
| **ProposalStorage** | Library | |||
|| getId | Internal 🔒 | | |
|| isEmpty | Internal 🔒 | | |
|| addData | Internal 🔒 | 🛑 | |
|| getData | Internal 🔒 | | |
|| updateData | Internal 🔒 | 🛑 | |
|| removeData | Internal 🔒 | 🛑 | |
||||||
| **IWETH** | Interface | |||
|| deposit | External ❗️ | 💵 |NO❗️ |
|| withdraw | External ❗️ | 🛑 |NO❗️ |
Expand All @@ -88,13 +102,6 @@
|| isEmpty | Internal 🔒 | | |
|| addNode | Internal 🔒 | 🛑 | |
||||||
| **MyProxy** | Implementation | Ownable, Proxy |||
|| <Constructor> | Public ❗️ | 🛑 | Ownable |
|| setImplementation | External ❗️ | 🛑 | onlyOwner |
|| getImplementation | External ❗️ | |NO❗️ |
|| _implementation | Internal 🔒 | | |
|| <Receive Ether> | External ❗️ | 💵 |NO❗️ |
||||||
| **Raffle** | Implementation | VRFConsumerBaseV2Plus, AutomationCompatibleInterface |||
|| <Constructor> | Public ❗️ | 🛑 | VRFConsumerBaseV2Plus |
|| initialize | Public ❗️ | 🛑 | onlyOwner |
Expand Down Expand Up @@ -123,18 +130,12 @@
|| setStaking | Public ❗️ | 🛑 | onlyOwner |
|| _concludeWithdraw | Internal 🔒 | 🛑 | |
||||||
| **VotingLinkedList** | Implementation | |||
|| getById | Public ❗️ | |NO❗️ |
|| isNotEmpty | Public ❗️ | |NO❗️ |
|| getHead | Public ❗️ | |NO❗️ |
|| getTail | Public ❗️ | |NO❗️ |
|| getId | Public ❗️ | |NO❗️ |
|| push | Public ❗️ | 🛑 |NO❗️ |
|| pushStart | Public ❗️ | 🛑 |NO❗️ |
|| insert | Public ❗️ | 🛑 |NO❗️ |
|| deleteNode | Public ❗️ | 🛑 |NO❗️ |
|| clear | Public ❗️ | 🛑 |NO❗️ |
|| traverse | Public ❗️ | |NO❗️ |
| **MyProxy** | Implementation | Ownable, Proxy |||
|| <Constructor> | Public ❗️ | 🛑 | Ownable |
|| setImplementation | External ❗️ | 🛑 | onlyOwner |
|| getImplementation | External ❗️ | |NO❗️ |
|| _implementation | Internal 🔒 | | |
|| <Receive Ether> | External ❗️ | 💵 |NO❗️ |


### Legend
Expand Down

0 comments on commit 769a6c2

Please sign in to comment.