-
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.
feat: token, and full governance layout
- Loading branch information
Showing
7 changed files
with
224 additions
and
696 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Compatible with OpenZeppelin Contracts ^5.0.0 | ||
pragma solidity ^0.8.20; | ||
|
||
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
import { ERC20Permit, Nonces } from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol"; | ||
import { ERC20Votes } from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol"; | ||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
contract GovernanceToken is ERC20, ERC20Permit, ERC20Votes, Ownable { | ||
constructor( | ||
address initialOwner | ||
) | ||
ERC20("GovernanceToken", "GTK") | ||
ERC20Permit("GovernanceToken") | ||
Ownable(initialOwner) | ||
{} | ||
|
||
function _update( | ||
address from, | ||
address to, | ||
uint256 value | ||
) internal override(ERC20, ERC20Votes) { | ||
super._update(from, to, value); | ||
} | ||
|
||
function nonces( | ||
address owner | ||
) public view override(ERC20Permit, Nonces) returns (uint256) { | ||
return super.nonces(owner); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,65 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
struct State { | ||
enum ProposalState { | ||
Created, | ||
Executed, | ||
Canceled | ||
} | ||
|
||
struct ProposalStorageState { | ||
mapping(bytes32 => Proposal) proposals; | ||
bytes32 lastProposalId; | ||
} | ||
|
||
// Timestamps are in block numbers | ||
struct Proposal { | ||
uint256 id; | ||
address sender; | ||
bytes32[] signatures; | ||
bytes32[] calldatas; | ||
uint256 proposedAt; | ||
bytes32 description; | ||
//--- | ||
uint256 votingStartedAt; | ||
bool executed; | ||
uint256 forVotes; | ||
uint256 againstVotes; | ||
ProposalState state; | ||
} | ||
|
||
library ProposalStorage { | ||
function getId(Proposal memory _params) internal pure returns (bytes32) { | ||
return | ||
keccak256( | ||
abi.encodePacked( | ||
_params.id, | ||
_params.sender, | ||
_params.signatures, | ||
_params.calldatas, | ||
_params.proposedAt, | ||
_params.votingStartedAt, | ||
_params.executed | ||
_params.description | ||
) | ||
); | ||
} | ||
|
||
function isEmpty( | ||
State storage state, | ||
ProposalStorageState storage state, | ||
bytes32 id | ||
) internal view returns (bool) { | ||
return state.proposals[id].sender == address(0); | ||
} | ||
|
||
function addData( | ||
State storage state, | ||
Proposal memory _Proposal | ||
) internal returns (bytes32) { | ||
bytes32 id = getId(_Proposal); | ||
state.proposals[id] = _Proposal; | ||
ProposalStorageState storage state, | ||
Proposal memory proposal | ||
) internal returns (bytes32 id) { | ||
id = getId(proposal); | ||
state.proposals[id] = proposal; | ||
state.lastProposalId = id; | ||
|
||
return id; | ||
} | ||
|
||
function getData( | ||
State storage state, | ||
ProposalStorageState storage state, | ||
bytes32 id | ||
) internal view returns (Proposal memory) { | ||
) internal view returns (Proposal storage) { | ||
return state.proposals[id]; | ||
} | ||
|
||
function updateData( | ||
State storage state, | ||
bytes32 id, | ||
Proposal memory _Proposal | ||
) 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
Oops, something went wrong.