Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do Governance Proposals with Signatures #429

Merged
merged 20 commits into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions contracts/utils/GovProposalHelper.sol

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to add the description for the functions and parameters

Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,34 @@ struct GovProposal {
library GovProposalHelper {
function id(GovProposal memory prop) internal view returns (uint256 proposalId) {
bytes32 descriptionHash = keccak256(bytes(prop.description));
(address[] memory targets, uint256[] memory values, bytes[] memory calldatas) = getParams(prop);
(address[] memory targets, uint256[] memory values,,, bytes[] memory calldatas) = getParams(prop);

proposalId = uint256(keccak256(abi.encode(targets, values, calldatas, descriptionHash)));
}

function getParams(GovProposal memory prop)
internal
view
returns (address[] memory targets, uint256[] memory values, bytes[] memory calldatas)
returns (
address[] memory targets,
uint256[] memory values,
string[] memory sigs,
bytes[] memory data,
bytes[] memory calldatas
)
{
uint256 actionLen = prop.actions.length;
targets = new address[](actionLen);
values = new uint256[](actionLen);

string[] memory sigs = new string[](actionLen);
bytes[] memory data = new bytes[](actionLen);
sigs = new string[](actionLen);
data = new bytes[](actionLen);

for (uint256 i = 0; i < actionLen; ++i) {
targets[i] = prop.actions[i].target;
values[i] = prop.actions[i].value;
sigs[i] = prop.actions[i].fullsig;
data[i] = prop.actions[i].data;
values[i] = prop.actions[i].value;
}

calldatas = _encodeCalldata(sigs, data);
Expand Down Expand Up @@ -77,10 +83,11 @@ library GovProposalHelper {
}

function getProposeCalldata(GovProposal memory prop) internal view returns (bytes memory proposeCalldata) {
(address[] memory targets, uint256[] memory values, bytes[] memory calldatas) = getParams(prop);
(address[] memory targets, uint256[] memory values, string[] memory sigs, bytes[] memory data,) =
getParams(prop);

proposeCalldata = abi.encodeWithSignature(
"propose(address[],uint256[],bytes[],string)", targets, values, calldatas, prop.description
"propose(address[],uint256[],string[], bytes[],string)", targets, values, sigs, data, prop.description
);
}

Expand Down Expand Up @@ -148,7 +155,7 @@ library GovProposalHelper {
if (state == IGovernor.ProposalState.Active) {
console.log("Voting on proposal...");
// Vote on proposal
governance.castVote(proposalId, 1);
try governance.castVote(proposalId, 1) {} catch {}
// Wait for voting to end
vm.roll(governance.proposalDeadline(proposalId) + 20);
vm.warp(block.timestamp + 2 days);
Expand Down
Loading