// SPDX-License-Identifier: MIT pragma solidity ^0.6.12; import {Parameters} from "@proprietary/Parameters.sol"; import {IGovernance} from "@interfaces/IGovernance.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {Test} from "@forge-std/Test.sol"; contract MockProposal is Parameters, Test { IGovernance internal governance = IGovernance(_governanceAddress); uint256 public constant TEST_PRIVATE_KEY_ONE = 0x66ddbd7cbe4a566df405f6ded0b908c669f88cdb1656380c050e3a457bd21df0; uint256 public constant TEST_PRIVATE_KEY_TWO = 0xa4c8c98120e77741a87a116074a2df4ddb20d1149069290fd4a3d7ee65c55064; address public constant TEST_ADDRESS_ONE = 0x118251976c65AFAf291f5255450ddb5b6A4d8B88; address public constant TEST_ADDRESS_TWO = 0x63aE7d90Eb37ca39FC62dD9991DbEfeE70673a20; uint256 public constant PROPOSAL_VOTING_DURATION = 5 days; uint256 public constant PROPOSAL_LOCKED_DURATION = 2 days; uint256 public constant PROPOSAL_DURATION = PROPOSAL_VOTING_DURATION + PROPOSAL_LOCKED_DURATION; uint256 public constant PROPOSAL_EXECUTION_MAX_DURATION = 3 days; uint256 public constant PROPOSAL_THRESHOLD = 25000 ether; string public constant PROPOSAL_DESCRIPTION = "{title:'Some proposal',description:''}"; address public constant VERIFIER_ADDRESS = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C; bytes32 public constant PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); bytes32 public constant EIP712_DOMAIN = keccak256( abi.encode( keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"), keccak256(bytes("TornadoCash")), keccak256(bytes("1")), 1, VERIFIER_ADDRESS ) ); uint16 public constant PERMIT_FUNC_SELECTOR = uint16(0x1901); function executeProposal(address proposalAddress) public { uint256 proposalId = voteAndCreateProposal(proposalAddress); governance.execute(proposalId); } function waitUntilExecutable() internal { vm.warp(block.timestamp + PROPOSAL_DURATION); } function voteAndCreateProposal(address proposalAddress) public returns (uint256) { retrieveAndLockBalance(TEST_PRIVATE_KEY_ONE, TEST_ADDRESS_ONE, PROPOSAL_THRESHOLD); retrieveAndLockBalance(TEST_PRIVATE_KEY_TWO, TEST_ADDRESS_TWO, 1 ether); /* ----------PROPOSER------------ */ vm.startPrank(TEST_ADDRESS_ONE); uint256 proposalId = IGovernance(_governanceAddress).propose(proposalAddress, PROPOSAL_DESCRIPTION); // TIME-TRAVEL vm.warp(block.timestamp + 6 hours); IGovernance(_governanceAddress).castVote(proposalId, true); vm.stopPrank(); /* ------------------------------ */ /* -------------VOTER-------------*/ vm.startPrank(TEST_ADDRESS_TWO); IGovernance(_governanceAddress).castVote(proposalId, true); vm.stopPrank(); /* ------------------------------ */ return proposalId; } function retrieveAndLockBalance(uint256 privateKey, address voter, uint256 amount) internal { uint256 lockTimestamp = block.timestamp + PROPOSAL_DURATION; bytes32 messageHash = keccak256( abi.encodePacked( PERMIT_FUNC_SELECTOR, EIP712_DOMAIN, keccak256(abi.encode(PERMIT_TYPEHASH, voter, _governanceAddress, amount, 0, lockTimestamp)) ) ); /* ----------GOVERNANCE------- */ vm.startPrank(_governanceAddress); IERC20(_tokenAddress).transfer(voter, amount); vm.stopPrank(); /* ----------------------------*/ (uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, messageHash); /* ----------VOTER------------ */ vm.startPrank(voter); IGovernance(_governanceAddress).lock(voter, amount, lockTimestamp, v, r, s); vm.stopPrank(); /* ----------------------------*/ } }