Initial commit

This commit is contained in:
Theo 2023-06-05 17:30:37 +02:00
commit c5f127cf2e
12 changed files with 5632 additions and 0 deletions

3
.env.example Normal file

@ -0,0 +1,3 @@
MAINNET_RPC_URL=
PRIVATE_KEY=
ETHERSCAN_KEY=

27
.gitignore vendored Normal file

@ -0,0 +1,27 @@
# Compiler files
cache/
out/
# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/
# Docs
docs/
# Dotenv file
.env
.env.bat
# Node modules
node_modules/
# yarn
yarn.lock
# VSCode
.vscode
# Packages source
node_modules

3
.gitmodules vendored Normal file

@ -0,0 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std

26
foundry.toml Normal file

@ -0,0 +1,26 @@
[profile.default]
# General
src = 'src'
out = 'out'
libs = ["node_modules", "lib"]
# Compiler
auto_detect_solc = true
via_ir = true
optimizer = true
optimizer_runs = 200
# Network
chain_id = 1
# Tests
[profile.ci]
verbosity = 3
[rpc_endpoints]
mainnet = "${MAINNET_RPC_URL}"
[fmt]
line_length = 140
number_underscore = 'thousands'
bracket_spacing = true

5222
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

18
package.json Normal file

@ -0,0 +1,18 @@
{
"name": "proposal-template",
"version": "1.0.0",
"repository": "https://git.tornado.ws/Theo/proposal-template",
"author": "AlienTornadosaurusHex",
"license": "MIT",
"private": false,
"dependencies": {
"@ensdomains/ens-contracts": "^0.0.21",
"@openzeppelin/contracts": "^4.9.0",
"@openzeppelin/upgrades-core": "^1.26.2",
"torn-token": "^1.0.4"
},
"optionalDependencies": {
"@gnosis.pm/ido-contracts": "^0.5.0",
"@gnosis.pm/safe-contracts": "1.3.0"
}
}

11
remappings.txt Normal file

@ -0,0 +1,11 @@
@proprietary/=src/proprietary/
@interfaces/=src/interfaces/
@root/=src/
@forge-std/=lib/forge-std/src/
@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/
@openzeppelin/upgrades/=node_modules/@openzeppelin/upgrades-core/
@ens/contracts/=node_modules/@ensdomains/ens-contracts/contracts/
@gnosis/contracts/=node_modules/@gnosis.pm/safe-contracts/contracts/
@gnosis/ido-contracts/=node_modules/@gnosis.pm/ido-contracts/contracts/
@torn-token/=node_modules/torn-token/

7
src/ExampleProposal.sol Normal file

@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
contract ExampleProposal {
function executeProposal() public { /* ... */ }
}

@ -0,0 +1,84 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
interface IGnosisSafe {
enum Operation {
Call,
DelegateCall
}
function NAME() external view returns (string memory);
function VERSION() external view returns (string memory);
function nonce() external view returns (uint256);
function domainSeparator() external view returns (bytes32);
function signedMessages(bytes32) external view returns (uint256);
function approvedHashes(address, bytes32) external view returns (uint256);
function setup(
address[] calldata _owners,
uint256 _threshold,
address to,
bytes calldata data,
address fallbackHandler,
address paymentToken,
uint256 payment,
address payable paymentReceiver
) external;
function execTransaction(
address to,
uint256 value,
bytes calldata data,
Operation operation,
uint256 safeTxGas,
uint256 baseGas,
uint256 gasPrice,
address gasToken,
address payable refundReceiver,
bytes calldata signatures
) external returns (bool success);
function requiredTxGas(address to, uint256 value, bytes calldata data, Operation operation)
external
returns (uint256);
function approveHash(bytes32 hashToApprove) external;
function signMessage(bytes calldata _data) external;
function isValidSignature(bytes calldata _data, bytes calldata _signature) external returns (bytes4);
function getMessageHash(bytes memory message) external view returns (bytes32);
function encodeTransactionData(
address to,
uint256 value,
bytes memory data,
Operation operation,
uint256 safeTxGas,
uint256 baseGas,
uint256 gasPrice,
address gasToken,
address refundReceiver,
uint256 _nonce
) external view returns (bytes memory);
function getTransactionHash(
address to,
uint256 value,
bytes memory data,
Operation operation,
uint256 safeTxGas,
uint256 baseGas,
uint256 gasPrice,
address gasToken,
address refundReceiver,
uint256 _nonce
) external view returns (bytes32);
}

@ -0,0 +1,55 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
enum ProposalState {
Pending,
Active,
Defeated,
Timelocked,
AwaitingExecution,
Executed,
Expired
}
struct Proposal {
// Creator of the proposal
address proposer;
// target addresses for the call to be made
address target;
// The block at which voting begins
uint256 startTime;
// The block at which voting ends: votes must be cast prior to this block
uint256 endTime;
// Current number of votes in favor of this proposal
uint256 forVotes;
// Current number of votes in opposition to this proposal
uint256 againstVotes;
// Flag marking whether the proposal has been executed
bool executed;
// Flag marking whether the proposal voting time has been extended
// Voting time can be extended once, if the proposal outcome has changed during CLOSING_PERIOD
bool extended;
}
interface IGovernance {
function initialized() external view returns (bool);
function initializing() external view returns (bool);
function EXECUTION_DELAY() external view returns (uint256);
function EXECUTION_EXPIRATION() external view returns (uint256);
function QUORUM_VOTES() external view returns (uint256);
function PROPOSAL_THRESHOLD() external view returns (uint256);
function VOTING_DELAY() external view returns (uint256);
function VOTING_PERIOD() external view returns (uint256);
function CLOSING_PERIOD() external view returns (uint256);
function VOTE_EXTEND_TIME() external view returns (uint256);
function torn() external view returns (address);
function proposals(uint256 index) external view returns (Proposal memory);
function lockedBalance(address account) external view returns (uint256);
function propose(address target, string memory description) external returns (uint256);
function castVote(uint256 proposalId, bool support) external;
function lock(address owner, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external;
function lockWithApproval(uint256 amount) external;
function execute(uint256 proposalId) external payable;
function state(uint256 proposalId) external view returns (ProposalState);
}

@ -0,0 +1,29 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
contract TornadoAddresses {
function getENSAddress() internal pure returns (address) {
return 0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e;
}
function getTornTokenAddress() internal pure returns (address) {
return 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C;
}
function getMultisigAddress() internal pure returns (address) {
return 0xb04E030140b30C27bcdfaafFFA98C57d80eDa7B4;
}
function getGovernanceProxyAddress() internal pure returns (address) {
return 0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce;
}
function getStakingProxyAddress() internal pure returns (address) {
return 0x5B3f656C80E8ddb9ec01Dd9018815576E9238c29;
}
function getRegistryProxyAddress() internal pure returns (address) {
return 0x58E8dCC13BE9780fC42E8723D8EaD4CF46943dF2;
}
}

@ -0,0 +1,147 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import { IGovernance, Proposal } from "@interfaces/IGovernance.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ERC20Permit } from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
import { Test } from "@forge-std/Test.sol";
import { TornadoAddresses } from "@proprietary/TornadoAddresses.sol";
contract TornadoProposalTest is Test, TornadoAddresses {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PERMIT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TEST DUMMIES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
address public constant TEST_REAL_ADDRESS_WITH_BALANCE = 0x9Ff3C1Bea9ffB56a78824FE29f457F066257DD58;
address public constant TEST_RELAYER_ADDRESS = 0x30F96AEF199B399B722F8819c9b0723016CEAe6C;
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;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ADDRESSES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
address public constant VERIFIER_ADDRESS = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GOVERNANCE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
string public constant PROPOSAL_DESCRIPTION = "{title:'Some proposal',description:''}";
uint256 public EXECUTION_DELAY;
uint256 public EXECUTION_EXPIRATION;
uint256 public QUORUM_VOTES;
uint256 public PROPOSAL_THRESHOLD;
uint256 public VOTING_DELAY;
uint256 public VOTING_PERIOD;
uint256 public CLOSING_PERIOD;
uint256 public VOTE_EXTEND_TIME;
IGovernance public immutable governance = IGovernance(getGovernanceProxyAddress());
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TEST UTILS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function setUp() public virtual {
vm.createSelectFork(vm.envString("MAINNET_RPC_URL"));
_fetchConfiguration();
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HELPERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function waitUntilExecutable(uint256 proposalId) internal {
uint256 proposalExecutableTime = getProposalExecutableTime(proposalId);
require(block.timestamp < proposalExecutableTime, "Too late to execute proposal");
vm.warp(proposalExecutableTime);
}
function easyPropose(address proposalAddress) public returns (uint256) {
retrieveAndLockBalance(TEST_PRIVATE_KEY_ONE, TEST_ADDRESS_ONE, QUORUM_VOTES);
retrieveAndLockBalance(TEST_PRIVATE_KEY_TWO, TEST_ADDRESS_TWO, 1 ether);
/* ----------PROPOSER------------ */
vm.startPrank(TEST_ADDRESS_ONE);
uint256 proposalId = governance.propose(proposalAddress, PROPOSAL_DESCRIPTION);
// TIME-TRAVEL
vm.warp(block.timestamp + 6 hours);
governance.castVote(proposalId, true);
vm.stopPrank();
/* ------------------------------ */
/* -------------VOTER-------------*/
vm.startPrank(TEST_ADDRESS_TWO);
governance.castVote(proposalId, true);
vm.stopPrank();
/* ------------------------------ */
return proposalId;
}
function retrieveAndLockBalance(uint256 privateKey, address voter, uint256 amount) internal {
uint256 lockTimestamp = block.timestamp + VOTING_PERIOD + EXECUTION_DELAY + 1 hours;
uint256 accountNonce = ERC20Permit(getTornTokenAddress()).nonces(voter);
bytes32 messageHash = keccak256(
abi.encodePacked(
PERMIT_FUNC_SELECTOR,
EIP712_DOMAIN,
keccak256(abi.encode(PERMIT_TYPEHASH, voter, getGovernanceProxyAddress(), amount, accountNonce, lockTimestamp))
)
);
/* ----------GOVERNANCE------- */
vm.startPrank(getGovernanceProxyAddress());
IERC20(getTornTokenAddress()).transfer(voter, amount);
vm.stopPrank();
/* ----------------------------*/
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, messageHash);
/* ----------VOTER------------ */
vm.startPrank(voter);
governance.lock(voter, amount, lockTimestamp, v, r, s);
vm.stopPrank();
/* ----------------------------*/
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GETTERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function getProposalExecutableTime(uint256 proposalId) internal view returns (uint256) {
Proposal memory proposal = IGovernance(getGovernanceProxyAddress()).proposals(proposalId);
return proposal.endTime + EXECUTION_DELAY + 1 hours;
}
function _fetchConfiguration() internal {
EXECUTION_DELAY = governance.EXECUTION_DELAY();
EXECUTION_EXPIRATION = governance.EXECUTION_EXPIRATION();
QUORUM_VOTES = governance.QUORUM_VOTES();
PROPOSAL_THRESHOLD = governance.PROPOSAL_THRESHOLD();
VOTING_DELAY = governance.VOTING_DELAY();
VOTING_PERIOD = governance.VOTING_PERIOD();
CLOSING_PERIOD = governance.CLOSING_PERIOD();
VOTE_EXTEND_TIME = governance.VOTE_EXTEND_TIME();
}
}