-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
155 additions
and
24 deletions.
There are no files selected for viewing
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
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
File renamed without changes.
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
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; | ||
|
||
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); | ||
} | ||
} |
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
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 GitHub Actions / codestyle
|
||
) 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 GitHub Actions / codestyle
|
||
) internal { | ||
state.proposals[id] = _Proposal; | ||
} | ||
|
||
function removeData(State storage state, bytes32 id) internal { | ||
delete state.proposals[id]; | ||
} | ||
} |
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
File renamed without changes.
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