2023-06-06 23:53:08 +03:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.8.19;
|
|
|
|
|
2023-07-20 00:41:25 +03:00
|
|
|
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
|
|
|
2023-06-06 23:53:08 +03:00
|
|
|
import { Utils } from "./Utils.sol";
|
|
|
|
import { Proposal, IGovernance } from "@interfaces/IGovernance.sol";
|
|
|
|
|
|
|
|
contract ProposalUtils is Utils {
|
|
|
|
IGovernance internal governance = IGovernance(governanceAddress);
|
|
|
|
|
|
|
|
function getProposalExecutableTime(uint256 proposalId) internal view returns (uint256) {
|
|
|
|
Proposal memory proposal = getProposal(proposalId);
|
|
|
|
return proposal.endTime + PROPOSAL_LOCKED_DURATION + 1 seconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getProposal(uint256 proposalId) internal view returns (Proposal memory) {
|
|
|
|
return governance.proposals(proposalId);
|
|
|
|
}
|
|
|
|
|
|
|
|
function hasProposal(uint256 proposalId) internal view returns (bool) {
|
|
|
|
return governance.proposalCount() >= proposalId;
|
|
|
|
}
|
|
|
|
|
|
|
|
function waitUntilExecutable(uint256 proposalId) internal {
|
|
|
|
uint256 proposalExecutableTime = getProposalExecutableTime(proposalId);
|
|
|
|
require(block.timestamp < proposalExecutableTime + PROPOSAL_EXECUTION_MAX_DURATION, "Too late to execute proposal");
|
|
|
|
|
|
|
|
vm.warp(proposalExecutableTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
function proposeAndVote(address proposalAddress) public returns (uint256) {
|
2023-06-06 23:57:07 +03:00
|
|
|
retrieveAndLockBalance(TEST_PRIVATE_KEY_ONE, TEST_ADDRESS_ONE, PROPOSAL_QOURUM_THRESHOLD + 1 ether);
|
2023-06-06 23:53:08 +03:00
|
|
|
|
2023-06-06 23:57:07 +03:00
|
|
|
/* ----------PROPOSE------------ */
|
2023-06-06 23:53:08 +03:00
|
|
|
vm.startPrank(TEST_ADDRESS_ONE);
|
|
|
|
|
|
|
|
uint256 proposalId = governance.propose(proposalAddress, PROPOSAL_DESCRIPTION);
|
|
|
|
|
2023-06-06 23:57:07 +03:00
|
|
|
/* ------------------------------ */
|
|
|
|
|
2023-06-06 23:53:08 +03:00
|
|
|
// TIME-TRAVEL
|
|
|
|
vm.warp(block.timestamp + 6 hours);
|
|
|
|
|
2023-06-06 23:57:07 +03:00
|
|
|
/* ------------VOTE-------------- */
|
2023-06-06 23:53:08 +03:00
|
|
|
|
|
|
|
governance.castVote(proposalId, true);
|
2023-06-06 23:57:07 +03:00
|
|
|
|
2023-06-06 23:53:08 +03:00
|
|
|
vm.stopPrank();
|
|
|
|
/* ------------------------------ */
|
|
|
|
|
|
|
|
return proposalId;
|
|
|
|
}
|
|
|
|
|
|
|
|
function proposeAndExecute(address proposalAddress) public {
|
|
|
|
uint256 proposalId = proposeAndVote(proposalAddress);
|
|
|
|
|
|
|
|
waitUntilExecutable(proposalId);
|
|
|
|
governance.execute(proposalId);
|
2023-07-20 00:41:25 +03:00
|
|
|
|
|
|
|
returnTokensToGovernanceAfterVoting(proposalId);
|
|
|
|
}
|
|
|
|
|
|
|
|
function returnTokensToGovernanceAfterVoting(uint256 proposalId) public {
|
|
|
|
uint256 retrievedAmount = PROPOSAL_QOURUM_THRESHOLD + 1 ether;
|
|
|
|
|
|
|
|
uint256 proposalExecutableTime = getProposalExecutableTime(proposalId);
|
|
|
|
uint256 tokensUnlockTime = proposalExecutableTime + PROPOSAL_VOTE_EXTEND_TIME + PROPOSAL_EXECUTION_MAX_DURATION + 1 seconds;
|
|
|
|
|
2023-07-28 09:00:21 +03:00
|
|
|
if (block.timestamp < tokensUnlockTime) vm.warp(tokensUnlockTime);
|
2023-07-20 00:41:25 +03:00
|
|
|
|
|
|
|
vm.startPrank(TEST_ADDRESS_ONE);
|
|
|
|
|
|
|
|
governance.unlock(retrievedAmount);
|
2023-07-28 09:00:21 +03:00
|
|
|
IERC20(tornTokenAddress).transfer(governanceAddress, retrievedAmount);
|
2023-07-20 00:41:25 +03:00
|
|
|
|
|
|
|
vm.stopPrank();
|
2023-06-06 23:53:08 +03:00
|
|
|
}
|
|
|
|
}
|