Governance deployment scripts (#684)

* Add foundry deployment script and config

* Add generated by foundry build artifact for Treasury

* Add shortcut commands for goerli deployment

* Switch to a production version of predicting a deployment address

* Lower gas price

* Fix a copy-paste error

* Productionise and final test
This commit is contained in:
Elena 2023-04-05 10:06:07 +03:00 committed by GitHub
parent b7bf5b5dfe
commit 3574ea5b27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12890 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -15,10 +15,15 @@ via_ir = true
[profile.integration]
match_path = "test/integration/*.sol"
gas_price = 31_000_000_000
[rpc_endpoints]
goerli = "${GOERLI_RPC_URL}"
mainnet = "${MAINNET_RPC_URL}"
[etherscan]
goerli = { key = "${ETHERSCAN_API_KEY}" }
[profile.smt.model_checker]
engine = 'chc'
timeout = 10_000

View File

@ -11,7 +11,10 @@
"test": "forge test",
"build": "forge build",
"build:smt": "FOUNDRY_PROFILE=smt forge build",
"test:integration": "source .env && FOUNDRY_PROFILE=integration forge test --fork-url $MAINNET_RPC_URL --fork-block-number 16884148 -vvv"
"test:integration": "source .env && FOUNDRY_PROFILE=integration forge test --fork-url $MAINNET_RPC_URL --fork-block-number 16884148 -vvv",
"goerli:deploy:zrxtoken": "source .env && forge script script/DeployToken.s.sol:Deploy --rpc-url $GOERLI_RPC_URL --broadcast --slow -vvvv",
"goerli:deploy:governance": "source .env && forge script script/DeployGovernance.s.sol:Deploy --rpc-url $GOERLI_RPC_URL --broadcast --slow -vvvv",
"mainnet:deploy:governance": "source .env && forge script script/DeployGovernance.s.sol:Deploy --rpc-url $MAINNET_RPC_URL --broadcast --slow -vvvv"
},
"repository": {
"type": "git",

View File

@ -0,0 +1,78 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
import "forge-std/Script.sol";
import "forge-std/console.sol";
import "forge-std/console2.sol";
import "@openzeppelin/token/ERC20/IERC20.sol";
import "@openzeppelin/proxy/ERC1967/ERC1967Proxy.sol";
import "../src/ZRXWrappedToken.sol";
import "../src/ZeroExVotes.sol";
import "../src/ZeroExTimelock.sol";
import "../src/ZeroExProtocolGovernor.sol";
import "../src/ZeroExTreasuryGovernor.sol";
contract Deploy is Script {
address internal constant DEPLOYER = 0xEf37aD2BACD70119F141140f7B5E46Cd53a65fc4;
address internal constant ZRX_TOKEN = 0xE41d2489571d322189246DaFA5ebDe1F4699F498;
address internal constant TREASURY = 0x0bB1810061C2f5b2088054eE184E6C79e1591101;
address internal constant EXCHANGE = 0xDef1C0ded9bec7F1a1670819833240f027b25EfF;
address payable internal constant SECURITY_COUNCIL = payable(DEPLOYER);
uint256 internal constant QUADRATIC_THRESHOLD = 1000000e18;
function setUp() public {}
function run() external {
vm.startBroadcast(vm.envAddress("DEPLOYER"));
console2.log("Zrx Token", ZRX_TOKEN);
address wTokenPrediction = predict(DEPLOYER, vm.getNonce(DEPLOYER) + 2);
ZeroExVotes votesImpl = new ZeroExVotes(wTokenPrediction, QUADRATIC_THRESHOLD);
ERC1967Proxy votesProxy = new ERC1967Proxy(address(votesImpl), abi.encodeCall(votesImpl.initialize, ()));
ZRXWrappedToken wToken = new ZRXWrappedToken(IERC20(ZRX_TOKEN), ZeroExVotes(address(votesProxy)));
assert(address(wToken) == wTokenPrediction);
console2.log("Wrapped Token", address(wToken));
ZeroExVotes votes = ZeroExVotes(address(votesProxy));
console2.log("Votes", address(votes));
address[] memory proposers = new address[](0);
address[] memory executors = new address[](0);
ZeroExTimelock protocolTimelock = new ZeroExTimelock(3 days, proposers, executors, DEPLOYER);
console2.log("Protocol timelock", address(protocolTimelock));
ZeroExProtocolGovernor protocolGovernor = new ZeroExProtocolGovernor(
IVotes(address(votes)),
protocolTimelock,
SECURITY_COUNCIL
);
protocolTimelock.grantRole(protocolTimelock.PROPOSER_ROLE(), address(protocolGovernor));
protocolTimelock.grantRole(protocolTimelock.EXECUTOR_ROLE(), address(protocolGovernor));
protocolTimelock.grantRole(protocolTimelock.CANCELLER_ROLE(), address(protocolGovernor));
console2.log("Protocol governor", address(protocolGovernor));
ZeroExTimelock treasuryTimelock = new ZeroExTimelock(2 days, proposers, executors, DEPLOYER);
console2.log("Treasury timelock", address(treasuryTimelock));
ZeroExTreasuryGovernor treasuryGovernor = new ZeroExTreasuryGovernor(
IVotes(address(votes)),
treasuryTimelock,
SECURITY_COUNCIL
);
treasuryTimelock.grantRole(treasuryTimelock.PROPOSER_ROLE(), address(treasuryGovernor));
treasuryTimelock.grantRole(treasuryTimelock.EXECUTOR_ROLE(), address(treasuryGovernor));
treasuryTimelock.grantRole(treasuryTimelock.CANCELLER_ROLE(), address(treasuryGovernor));
console2.log("Treasury governor", address(treasuryGovernor));
console2.log(unicode"0x governance deployed successfully 🎉");
vm.stopBroadcast();
}
function predict(address deployer, uint256 nonce) internal pure returns (address) {
require(nonce > 0 && nonce < 128, "Invalid nonce");
return address(uint160(uint256(keccak256(abi.encodePacked(bytes2(0xd694), deployer, bytes1(uint8(nonce)))))));
}
}

View File

@ -0,0 +1,22 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
import "forge-std/Script.sol";
import "forge-std/console2.sol";
contract Deploy is Script {
function setUp() public {}
function run() external {
vm.startBroadcast(vm.envAddress("DEPLOYER"));
bytes memory _bytecode = vm.getCode("./ZRXToken.json");
address zrxToken;
assembly {
zrxToken := create(0, add(_bytecode, 0x20), mload(_bytecode))
}
console2.log("Zrx Token", zrxToken);
console2.log(unicode"Zrx Token deployed successfully 🎉");
vm.stopBroadcast();
}
}