initialise

This commit is contained in:
gozzy 2023-04-13 23:36:34 +00:00
commit 0aceb78423
14 changed files with 307 additions and 0 deletions

4
.gitmodules vendored Normal file
View File

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

8
README.md Normal file
View File

@ -0,0 +1,8 @@
## Requirements
* NodeJS
* Foundryup
## Testing
`npm run test`

7
foundry.toml Normal file
View File

@ -0,0 +1,7 @@
[profile.default]
src = 'src'
out = 'out'
libs = ["node_modules", "lib"]
chain_id = 1
# See more config options https://github.com/foundry-rs/foundry/tree/master/config

15
package.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "relayer-penalty-proposal",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"lib": "lib",
"test": "test"
},
"scripts": {
"test": "forge test -vvvvv --fork-url https://api.securerpc.com/v1 --block-number 17011300"
},
"author": "",
"license": "ISC"
}

6
remappings.txt Normal file
View File

@ -0,0 +1,6 @@
@proprietary/=src/proprietary/
@interfaces/=src/interfaces/
@root/=src/
@forge-std/=lib/forge-std/src/

60
src/Proposal.sol Normal file
View File

@ -0,0 +1,60 @@
pragma solidity 0.8.1;
import "@interfaces/ISablier.sol";
import "@interfaces/IERC20.sol";
import "@interfaces/IENSResolver.sol";
import "@interfaces/IENSRegistry.sol";
contract Proposal {
function updateENSIPFSConfig() internal {
bytes32 CLASSIC_ENS_NODE = 0xe6ae31d630cc7a8279c0f1c7cbe6e7064814c47d1785fa2703d9ae511ee2be0c;
bytes32 CLASSIC_ENS_DOCS_LABEL_HASH = 0x25e5cde5b364d3ffc5a7c8fecda7cf863701488fc2dd91fb4c9e6c59e62bad4a;
bytes32 CLASSIC_ENS_RELAYERS_NETWORK_SUBNODE = 0x4e37047f2c961db41dfb7d38cf79ca745faf134a8392cfb834d3a93330b9108d;
bytes memory CLASSIC_ROOT_IPFS_HASH = hex"e30101701220d422ef6e800db34f50101daa4ea6b04365ab44b49bf58c00b54c1067befb7370";
bytes memory CLASSIC_DOCS_IPFS_HASH = hex"e30101701220d422ef6e800db34f50101daa4ea6b04365ab44b49bf58c00b54c1067befb7370";
bytes memory CLASSIC_RELAYERS_NETWORK_IPFS_HASH = hex"e30101701220d422ef6e800db34f50101daa4ea6b04365ab44b49bf58c00b54c1067befb7370";
address _resolverAddress = 0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41;
address _registryAddress = 0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e;
address _governanceAddress = 0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce;
bytes32 CLASSIC_ENS_DOCS_SUBNODE = IENSRegistry(_registryAddress).setSubnodeOwner(CLASSIC_ENS_NODE, CLASSIC_ENS_DOCS_LABEL_HASH, _governanceAddress);
IENSRegistry(_registryAddress).setSubnodeRecord(CLASSIC_ENS_NODE, CLASSIC_ENS_DOCS_LABEL_HASH, _governanceAddress, _resolverAddress, 0);
IENSResolver(_resolverAddress).setContenthash(CLASSIC_ENS_NODE, CLASSIC_ROOT_IPFS_HASH);
IENSResolver(_resolverAddress).setContenthash(CLASSIC_ENS_DOCS_SUBNODE, CLASSIC_DOCS_IPFS_HASH);
IENSResolver(_resolverAddress).setContenthash(CLASSIC_ENS_RELAYERS_NETWORK_SUBNODE, CLASSIC_RELAYERS_NETWORK_IPFS_HASH);
}
function appendSablierRemuneration() internal {
uint256 FISCAL_Q_DURATION = 91 days;
uint256 RENUMERATION_START_TS = block.timestamp;
uint256 RENUMERATION_AMOUNT = 13363 ether;
uint256 RENUMERATION_NORMALISED_AMOUNT = RENUMERATION_AMOUNT - (RENUMERATION_AMOUNT % FISCAL_Q_DURATION);
address RENUMERATION_ADDRESS = 0x40d16C473CB7bF5fAB9713b27A4562EAa6f915d1;
address _tokenAddress = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C;
address _sablierAddress = 0xCD18eAa163733Da39c232722cBC4E8940b1D8888;
IERC20(_tokenAddress).approve(_sablierAddress, RENUMERATION_NORMALISED_AMOUNT);
ISablier(_sablierAddress).createStream(
RENUMERATION_ADDRESS,
RENUMERATION_NORMALISED_AMOUNT,
_tokenAddress,
RENUMERATION_START_TS,
RENUMERATION_START_TS + FISCAL_Q_DURATION
);
}
function executeProposal() external {
updateENSIPFSConfig();
appendSablierRemuneration();
}
}

View File

@ -0,0 +1,9 @@
pragma solidity 0.8.1;
interface IENSRegistry {
function setSubnodeOwner(bytes32 node, bytes32 label, address owner) external returns(bytes32);
function setSubnodeRecord(bytes32 node, bytes32 label, address owner, address resolver, uint64 ttl) external;
}

View File

@ -0,0 +1,9 @@
pragma solidity 0.8.1;
interface IENSResolver {
function setContenthash(bytes32 node, bytes memory hash) external;
function contenthash(bytes32 node) external returns (bytes memory);
}

13
src/interfaces/IERC20.sol Normal file
View File

@ -0,0 +1,13 @@
pragma solidity 0.8.1;
interface IERC20 {
function transfer(address to, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
function balanceOf(address owner) external returns (uint256);
function approve(address spender, uint256 amount) external;
}

View File

@ -0,0 +1,20 @@
pragma solidity ^0.8.1;
interface IGovernance {
function propose(address target, string memory description) external returns (uint256);
function castVote(uint256 proposalId, bool support) external;
function execute(uint256 proposalId) external payable;
function lock(
address owner,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
}

View File

@ -0,0 +1,13 @@
pragma solidity ^0.8.1;
interface ISablier {
function createStream(
address recipent,
uint256 deposit,
address tokenAddress,
uint256 startTime,
uint256 stopTime
) external returns (uint256);
}

32
src/proprietary/Mock.sol Normal file
View File

@ -0,0 +1,32 @@
pragma solidity ^0.8.1;
contract Mock {
uint256 constant TEST_PRIVATE_KEY_ONE = 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80;
uint256 constant TEST_PRIVATE_KEY_TWO = 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d;
address constant TEST_ADDRESS_ONE = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;
address constant TEST_ADDRESS_TWO = 0x70997970C51812dc3A010C7d01b50e0d17dc79C8;
uint256 constant PROPOSAL_DURATION = 7 days;
uint256 constant PROPOSAL_THRESHOLD = 25000 ether;
string constant PROPOSAL_DESCRIPTION = "{title:'Proposal #17: Remuneration and ENS IPFS updates',description:''}";
address constant VERIFIER_ADDRESS = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C;
bytes32 constant PERMIT_TYPEHASH = keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
);
bytes32 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 constant PERMIT_FUNC_SELECTOR = uint16(0x1901);
}

View File

@ -0,0 +1,28 @@
pragma solidity ^0.8.1;
contract Parameters {
// Remuneration
uint256 public FISCAL_Q_DURATION = 91 days;
uint256 public RENUMERATION_AMOUNT = 13363 ether;
uint256 public RENUMERATION_NORMALISED_AMOUNT = RENUMERATION_AMOUNT - (RENUMERATION_AMOUNT % FISCAL_Q_DURATION);
address public RENUMERATION_ADDRESS = 0x40d16C473CB7bF5fAB9713b27A4562EAa6f915d1;
// ENS IPFS configuration
bytes32 CLASSIC_ENS_ROOT_SUBNODE = 0xe6ae31d630cc7a8279c0f1c7cbe6e7064814c47d1785fa2703d9ae511ee2be0c;
bytes32 CLASSIC_ENS_DOCS_SUBNODE = 0xe6ae31d630cc7a8279c0f1c7cbe6e7064814c47d1785fa2703d9ae511ee2be0c;
bytes32 CLASSIC_ENS_RELAYERS_NETWORK_SUBNODE = 0xe6ae31d630cc7a8279c0f1c7cbe6e7064814c47d1785fa2703d9ae511ee2be0c;
bytes CLASSIC_ROOT_IPFS_HASH = hex"e30101701220d422ef6e800db34f50101daa4ea6b04365ab44b49bf58c00b54c1067befb7370";
bytes CLASSIC_DOCS_IPFS_HASH = hex"e30101701220d422ef6e800db34f50101daa4ea6b04365ab44b49bf58c00b54c1067befb7370";
bytes CLASSIC_RELAYERS_NETWORK_IPFS_HASH = hex"e30101701220d422ef6e800db34f50101daa4ea6b04365ab44b49bf58c00b54c1067befb7370";
// Beneficary addresses
address public _governanceAddress = 0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce;
address public _tokenAddress = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C;
address public _sablierAddress = 0xCD18eAa163733Da39c232722cBC4E8940b1D8888;
address public registryAddress = 0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e;
address public _resolverAddress = 0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41;
}

83
test/Proposal.t.sol Normal file
View File

@ -0,0 +1,83 @@
pragma solidity ^0.8.1;
import "@interfaces/IGovernance.sol";
import "@interfaces/IERC20.sol";
import "@proprietary/Parameters.sol";
import "@proprietary/Mock.sol";
import "@root/Proposal.sol";
import "@forge-std/Test.sol";
contract ProposalTest is Test, Parameters, Mock {
modifier conditionStateChecks() {
checkParameters();
_;
checkResults();
}
function testProposal()
conditionStateChecks
public {
uint256 proposalId = voteAndCreateProposal(address(new Proposal()));
IGovernance(_governanceAddress).execute(proposalId);
}
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();
/* ------------------------------ */
// TIME-TRAVEL
vm.warp(block.timestamp + PROPOSAL_DURATION);
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();
/* ----------------------------*/
}
function checkParameters() internal {}
function checkResults() internal {}
}