Skip to content

Commit

Permalink
36: add metadata to governance contract
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 authored Oct 28, 2022
1 parent a77964b commit f69401c
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 111 deletions.
59 changes: 37 additions & 22 deletions contracts/CollectiveGovernance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ contract CollectiveGovernance is Governance, VoteStrategy, ERC165 {

uint256 public immutable _maximumBaseFeeRebate;

bytes32 public immutable _communityName;

string public _communityUrl;

string public _communityDescription;

/// @notice voting is open or not
mapping(uint256 => bool) private isVoteOpenByProposalId;

Expand All @@ -100,24 +94,16 @@ contract CollectiveGovernance is Governance, VoteStrategy, ERC165 {
/// @param _governanceStorage The storage contract for this governance
/// @param _gasUsedRebate The maximum rebate for gas used
/// @param _baseFeeRebate The maximum base fee rebate
/// @param _name The community name
/// @param _url The Url for this project
/// @param _description The community description
///
constructor(
address[] memory _supervisorList,
VoterClass _class,
Storage _governanceStorage,
TimeLocker _timeLocker,
uint256 _gasUsedRebate,
uint256 _baseFeeRebate,
bytes32 _name,
string memory _url,
string memory _description
uint256 _baseFeeRebate
) {
require(_supervisorList.length > 0, "Supervisor required");
require(Constant.len(_url) <= Constant.STRING_DATA_LIMIT, "Url too large");
require(Constant.len(_description) <= Constant.STRING_DATA_LIMIT, "Description too large");
require(_gasUsedRebate >= Constant.MAXIMUM_REBATE_GAS_USED, "Insufficient gas used rebate");
require(_baseFeeRebate >= Constant.MAXIMUM_REBATE_BASE_FEE, "Insufficient base fee rebate");

Expand All @@ -127,9 +113,6 @@ contract CollectiveGovernance is Governance, VoteStrategy, ERC165 {
_communitySupervisorList = _supervisorList;
_maximumGasUsedRebate = _gasUsedRebate;
_maximumBaseFeeRebate = _baseFeeRebate;
_communityName = _name;
_communityUrl = _url;
_communityDescription = _description;
}

modifier requireVoteReady(uint256 _proposalId) {
Expand Down Expand Up @@ -191,7 +174,7 @@ contract CollectiveGovernance is Governance, VoteStrategy, ERC165 {

/// @notice Attach a transaction to the specified proposal.
/// If successfull, it will be executed when voting is ended.
/// @dev must be called prior to configuration
/// @dev required prior to calling configure
/// @param _proposalId the id of the proposal
/// @param _target the target address for this transaction
/// @param _value the value to pass to the call
Expand Down Expand Up @@ -224,6 +207,38 @@ contract CollectiveGovernance is Governance, VoteStrategy, ERC165 {
return transactionId;
}

/// @notice describe a proposal
/// @param _proposalId the numeric id of the proposed vote
/// @param _description the description
/// @param _url for proposed vote
/// @dev required prior to calling configure
function describe(
uint256 _proposalId,
string memory _description,
string memory _url
) external {
require(_storage.getSender(_proposalId) == msg.sender, "Not sender");
_storage.setProposalDescription(_proposalId, _description, msg.sender);
_storage.setProposalUrl(_proposalId, _url, msg.sender);
emit ProposalDescription(_proposalId, _description, _url);
}

/// @notice attach arbitrary metadata to proposal
/// @dev required prior to calling configure
/// @param _proposalId the id of the proposal
/// @param _name the name of the metadata field
/// @param _value the value of the metadata
/// @return uint256 the metadata id
function addMeta(
uint256 _proposalId,
bytes32 _name,
string memory _value
) external returns (uint256) {
uint256 metaId = _storage.addMeta(_proposalId, _name, _value, msg.sender);
emit ProposalMeta(_proposalId, _name, _value, msg.sender);
return metaId;
}

/// @notice configure an existing proposal by id
/// @param _proposalId The numeric id of the proposed vote
/// @param _quorumRequired The threshold of participation that is required for a successful conclusion of voting
Expand Down Expand Up @@ -622,19 +637,19 @@ contract CollectiveGovernance is Governance, VoteStrategy, ERC165 {
/// @notice return the name of the community
/// @return bytes32 the community name
function community() external view returns (bytes32) {
return _communityName;
return _storage.community();
}

/// @notice return the community url
/// @return string memory representation of url
function url() external view returns (string memory) {
return _communityUrl;
return _storage.url();
}

/// @notice return community description
/// @return string memory representation of community description
function description() external view returns (string memory) {
return _communityDescription;
return _storage.description();
}

function castVoteFor(uint256 _proposalId, uint256 _tokenId) private {
Expand Down
13 changes: 2 additions & 11 deletions contracts/CollectiveGovernanceFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,21 @@ contract CollectiveGovernanceFactory {
/// @param _timeLock The timelock for the contract
/// @param _gasUsedRebate The maximum rebate for gas used
/// @param _baseFeeRebate The maximum base fee rebate
/// @param _name The community name
/// @param _url The Url for this project
/// @param _description The community description
function create(
address[] memory _supervisorList,
VoterClass _class,
Storage _storage,
TimeLocker _timeLock,
uint256 _gasUsedRebate,
uint256 _baseFeeRebate,
bytes32 _name,
string memory _url,
string memory _description
uint256 _baseFeeRebate
) external returns (Governance) {
Governance governance = new CollectiveGovernance(
_supervisorList,
_class,
_storage,
_timeLock,
_gasUsedRebate,
_baseFeeRebate,
_name,
_url,
_description
_baseFeeRebate
);
return governance;
}
Expand Down
30 changes: 29 additions & 1 deletion contracts/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ interface Governance is IERC165 {
uint256 scheduleTime,
bytes32 txHash
);

/// @notice ProposalMeta attached
event ProposalMeta(uint256 proposalId, bytes32 name, string value, address sender);
/// @notice The proposal description
event ProposalDescription(uint256 proposalId, string description, string url);
/// @notice The proposal is now open for voting
event ProposalOpen(uint256 proposalId);
/// @notice Voting is now closed for voting
Expand All @@ -101,7 +106,7 @@ interface Governance is IERC165 {

/// @notice Attach a transaction to the specified proposal.
/// If successfull, it will be executed when voting is ended.
/// @dev must be called prior to configuration
/// @dev required prior to calling configure
/// @param _proposalId the id of the proposal
/// @param _target the target address for this transaction
/// @param _value the value to pass to the call
Expand All @@ -119,6 +124,29 @@ interface Governance is IERC165 {
uint256 _scheduleTime
) external returns (uint256);

/// @notice describe a proposal
/// @param _proposalId the numeric id of the proposed vote
/// @param _description the description
/// @param _url for proposed vote
/// @dev required prior to calling configure
function describe(
uint256 _proposalId,
string memory _description,
string memory _url
) external;

/// @notice attach arbitrary metadata to proposal
/// @dev requires supervisor
/// @param _proposalId the id of the proposal
/// @param _name the name of the metadata field
/// @param _value the value of the metadata
/// @return uint256 the metadata id
function addMeta(
uint256 _proposalId,
bytes32 _name,
string memory _value
) external returns (uint256);

/// @notice cancel a proposal if it is not yet open
/// @param _proposalId The numeric id of the proposed vote
function cancel(uint256 _proposalId) external;
Expand Down
10 changes: 5 additions & 5 deletions contracts/GovernanceBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,7 @@ contract GovernanceBuilder is GovernanceCreator, ERC165 {
_storage,
_timeLock,
_properties.maxGasUsed,
_properties.maxBaseFee,
_properties.name,
_properties.url,
_properties.description
_properties.maxBaseFee
);
address payable _governanceAddress = payable(address(_governance));
transferOwnership(_timeLock, _governanceAddress);
Expand Down Expand Up @@ -268,7 +265,10 @@ contract GovernanceBuilder is GovernanceCreator, ERC165 {
_properties.class,
_properties.minimumProjectQuorum,
_properties.minimumVoteDelay,
_properties.minimumVoteDuration
_properties.minimumVoteDuration,
_properties.name,
_properties.url,
_properties.description
);
emit StorageCreated(address(_storage));
return _storage;
Expand Down
38 changes: 37 additions & 1 deletion contracts/GovernanceStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ contract GovernanceStorage is Storage, ERC165, Ownable {
/// @notice The total number of proposals
uint256 private _proposalCount;

bytes32 public immutable _communityName;

string public _communityUrl;

string public _communityDescription;

/// @notice global list of proposed issues by id
mapping(uint256 => Proposal) public proposalMap;

Expand All @@ -90,20 +96,32 @@ contract GovernanceStorage is Storage, ERC165, Ownable {
/// @param _minimumQuorum the least possible quorum for any vote
/// @param _minimumDelay the least possible vote delay
/// @param _minimumDuration the least possible voting duration
/// @param _community The community name
/// @param _url The Url for this community
/// @param _description The community description
constructor(
VoterClass _class,
uint256 _minimumQuorum,
uint256 _minimumDelay,
uint256 _minimumDuration
uint256 _minimumDuration,
bytes32 _community,
string memory _url,
string memory _description
) {
require(_minimumDelay >= Constant.MINIMUM_VOTE_DELAY, "Delay not allowed");
require(_minimumDuration >= Constant.MINIMUM_VOTE_DURATION, "Duration not allowed");
require(_minimumQuorum >= Constant.MINIMUM_PROJECT_QUORUM, "Quorum invalid");
require(Constant.len(_url) <= Constant.STRING_DATA_LIMIT, "Url too large");
require(Constant.len(_description) <= Constant.STRING_DATA_LIMIT, "Description too large");
require(_class.isFinal(), "Voter Class modifiable");
_minimumVoteDelay = _minimumDelay;
_minimumVoteDuration = _minimumDuration;
_minimumProjectQuorum = _minimumQuorum;
_voterClass = _class;
_communityName = _community;
_communityUrl = _url;
_communityDescription = _description;

_proposalCount = 0;
}

Expand Down Expand Up @@ -943,6 +961,24 @@ contract GovernanceStorage is Storage, ERC165, Ownable {
return _minimumProjectQuorum;
}

/// @notice return the name of the community
/// @return bytes32 the community name
function community() external view returns (bytes32) {
return _communityName;
}

/// @notice return the community url
/// @return string memory representation of url
function url() external view returns (string memory) {
return _communityUrl;
}

/// @notice return community description
/// @return string memory representation of community description
function description() external view returns (string memory) {
return _communityDescription;
}

/// @notice return the name of this implementation
/// @return string memory representation of name
function name() external pure virtual returns (string memory) {
Expand Down
12 changes: 12 additions & 0 deletions contracts/Storage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,18 @@ interface Storage is IERC165 {
/// @return uint the least quorum allowed for any vote
function minimumProjectQuorum() external view returns (uint256);

/// @notice return the name of the community
/// @return bytes32 the community name
function community() external view returns (bytes32);

/// @notice return the community url
/// @return string memory representation of url
function url() external view returns (string memory);

/// @notice return community description
/// @return string memory representation of community description
function description() external view returns (string memory);

/// @notice return the name of this implementation
/// @return string memory representation of name
function name() external pure returns (string memory);
Expand Down
18 changes: 16 additions & 2 deletions contracts/StorageFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,28 @@ contract StorageFactory {
/// @param _minimumQuorum the least possible quorum
/// @param _minimumDelay the minimum voting delay for the project
/// @param _minimumDuration the least possible voting duration
/// @param _community The community name
/// @param _url The Url for this community
/// @param _description The community description
/// @return Storage the created instance
function create(
VoterClass _class,
uint256 _minimumQuorum,
uint256 _minimumDelay,
uint256 _minimumDuration
uint256 _minimumDuration,
bytes32 _community,
string memory _url,
string memory _description
) external returns (Storage) {
GovernanceStorage _storage = new GovernanceStorage(_class, _minimumQuorum, _minimumDelay, _minimumDuration);
GovernanceStorage _storage = new GovernanceStorage(
_class,
_minimumQuorum,
_minimumDelay,
_minimumDuration,
_community,
_url,
_description
);
_storage.transferOwnership(msg.sender);
emit StorageCreated(address(_storage), msg.sender);
return _storage;
Expand Down
Loading

0 comments on commit f69401c

Please sign in to comment.